Display sql database values in textboxes using the session id

420 views Asked by At

I am stuck at a situation where i want to display the data in sql server database into the feilds on web page when user login their account. So for that i have wrriten a code in a class file.

    Public Function FetchResult() As DataTable
    Dim str As String =     ConfigurationManager.ConnectionStrings("dbSurvey").ConnectionString
    Dim conn As New SqlConnection(str)

    Dim fetch As String = "Select * from table_name"
    Dim cmd As SqlCommand = New SqlCommand(fetch, conn)

    Dim objAdpt As SqlDataAdapter = New SqlDataAdapter(cmd)
    Dim objDt As DataTable = New DataTable()
    objAdpt.Fill(objDt)

    Return objDt
End Function

and calling this function in the login button click. so that after user login, they can see their existing information

Dim dta As DataTable = obj.FetchSurveyResult
        If MultiView1.ActiveViewIndex = 2 Then
              txtBox.Text = dta.Rows(0)("Location1")
        End If
0

There are 0 answers