0

Hi,

I am trying to populate a textbox with the database data taking in consideration the session state. Checking if the session variable has the same name as in database, it should display the rest of the information in text boxes. I have come up with the following code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

       'Defining the variables

        Dim sqlconnection As New MySqlConnection
        Dim sqlcommand As New MySqlCommand
        Dim dr As New MySqlDataReader

       'Checks if the session has been generated and passed on from the login page

       If Session("username") > "" Then
            lblwelcomenote.Text = "You are logged in as " & " " & Session("username")
        Else
            Response.Redirect("Default.aspx")
        End If

        'Checks the connection string

        sqlconnection.ConnectionString = ("server=localhost; database=medipoint; user id=root; password=1234;")

        'Opening the connection

        sqlconnection.Open()

        'Select Query checking the session variable name exists in the database

        sqlcommand.Connection = sqlconnection
        sqlcommand.CommandText = ("SELECT * FROM registeration WHERE username='" & Session("username") & "'")

        'Reading the data from the database

        dr = sqlcommand.ExecuteReader()

        dr.Read()

        'Data put into the text boxes

        txtfirstname.Text = dr(0).ToString
        txtlastname.Text = dr(1).ToString
        txtemail.Text = dr(2).ToString
        txtpassword.Text = dr(3).ToString



    End Sub

This code gives me an error. The error is given below:

'MySql.Data.MySqlClient.MySqlDataReader.Friend Sub New(cmd As MySql.Data.MySqlClient.MySqlCommand, statement As MySql.Data.MySqlClient.PreparableStatement, behavior As System.Data.CommandBehavior)' is not accessible in this context because it is 'Friend'

Can anyone please help me with this? What does this error mean. With the description it seems that it is giving me an error with mysqldatareader variable dr.

Any help regarding this code will be highly appreciated.

Regards,

Bilal A. Khan

1
Contributor
1
Reply
4
Views
5 Years
Discussion Span
Last Post by BilalAKhan
0

I have found the solution. Repalce the following:

Dim dr As New MySqlDataReader

with

Dim dr As MySqlDataReader

The code will start working.

Regards,

Bilal A. Khan

Edited by BilalAKhan

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.