What's wrong with this? I know i must have missed out something. But what's that i'm missing?

Dim ds As DataSet = New DataSet
        Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM Member WHERE MemberUserName = @MemberUserName", Conn)
        da.SelectCommand.Parameters.Add("@MemberUserName", SqlDbType.VarChar)



        da.SelectCommand.Parameters("@MemberUserName").Value = Session("Username")
 
        ' Fill DataSet with the data
        da.Fill(ds, "Member")
        Page.DataBind()

        txtbox_name.DataBind()
        txtbox_birthdate.DataBind()
        txtbox_nric.DataBind()
        txtbox_address.DataBind()
        txtbox_contact.DataBind()
        txtbox_email.DataBind()
        Page.DataBind()
        Conn.Close()

Dani AI

Generated

— the adapter fills a DataSet, but nothing in your code actually puts those field values into the TextBox.Text properties. Calling Page.DataBind() only evaluates declarative <%# ... %> data-binding expressions in the markup or binds controls that are inside a data-bound container (DetailsView/FormView/Repeater). It will not magically copy columns from a DataSet into plain TextBox controls unless those TextBoxes have binding expressions in the .aspx. 's comment about clearing bindings is a pattern you see in Windows Forms; it does not address the usual WebForms issue here.

A straightforward, reliable fix is to read the first DataRow and assign the values explicitly (with DBNull checks). Example:

If ds.Tables.Count > 0 AndAlso ds.Tables(0).Rows.Count > 0 Then
  Dim r As DataRow = ds.Tables(0).Rows(0)
  txtbox_name.Text = If(IsDBNull(r("MemberName")), "", r("MemberName").ToString())
  txtbox_email.Text = If(IsDBNull(r("Email")), "", r("Email").ToString())
  txtbox_birthdate.Text = If(IsDBNull(r("BirthDate")), "", Convert.ToDateTime(r("BirthDate")).ToString("yyyy-MM-dd"))
End If

If you prefer declarative binding, bind the DataTable to a DetailsView or FormView and use Eval/Bind in templates, for example:

<asp:DetailsView ID="dvMember" runat="server" AutoGenerateRows="False">
  <Fields>
    <asp:BoundField DataField="MemberName" HeaderText="Name" />
    <asp:BoundField DataField="Email" HeaderText="Email" />
  </Fields>
</asp:DetailsView>

and in code-behind:

dvMember.DataSource = ds.Tables(0)
dvMember.DataBind()

Quick troubleshooting and best practices: verify Session("Username") is not null, specify parameter size (e.g. Add("@MemberUserName", SqlDbType.VarChar, 50).Value = ...), check ds.Tables(0).Rows.Count before reading, handle DBNull to avoid errors, remove redundant Page.DataBind() calls, and use Using blocks for connections/commands to ensure proper disposal.

What's wrong with this? I know i must have missed out something. But what's that i'm missing?

Dim ds As DataSet = New DataSet
        Dim da As SqlDataAdapter = New SqlDataAdapter("SELECT * FROM Member WHERE MemberUserName = @MemberUserName", Conn)
        da.SelectCommand.Parameters.Add("@MemberUserName", SqlDbType.VarChar)



        da.SelectCommand.Parameters("@MemberUserName").Value = Session("Username")
 
        ' Fill DataSet with the data
        da.Fill(ds, "Member")
        Page.DataBind()

        txtbox_name.DataBind()
        txtbox_birthdate.DataBind()
        txtbox_nric.DataBind()
        txtbox_address.DataBind()
        txtbox_contact.DataBind()
        txtbox_email.DataBind()
        Page.DataBind()
        Conn.Close()

hi,
before u are adding the databinding to textboxes u have to clear there binding. if u dont do this first time when u run ur application it works but the next time it nowt works.
so before
txtbox_name.DataBind()
txtbox_birthdate.DataBind()
txtbox_nric.DataBind()
txtbox_address.DataBind()
txtbox_contact.DataBind()
txtbox_email.DataBind()
this code u clear binding of all these text boxes

Hope this will help U
Neeraj trivedi

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.