Results 1 to 2 of 2

Thread: [2.0] Is this code correct for databindings of textbox?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2007
    Posts
    240

    [2.0] Is this code correct for databindings of textbox?

    I have here the code:

    Code:
                        string sitecodeID = sitecodeList.SelectedValue;
    
                          string sqlSiteName = "Select SiteName from tblSite where sitecodeID = " + sitecodeID;
                            SqlDataAdapter daSiteName = new SqlDataAdapter(sqlSiteName, conn);
                            DataTable dtSiteName = new DataTable();
                            daSiteName.Fill(dtSiteName);
                            lblSiteName.Text = dtSiteName.Rows;
    I would like to databind the content of my database in this textbox.

    Is this correct?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Is this code correct for databindings of textbox?

    There's no data-binding going on there, nor do I see any mention of a TextBox. To bind a column to a TextBox you'd do something like this:
    vb Code:
    1. myTextBox.DataBindings.Add("Text", dtSiteName, "SiteName")
    The first parameter is the name of the control property to which to bind. The second parameter is the object containing the data. The third parameter is the name of the data source property to bind. In your case you're binding the "SiteName" column of dtSiteName to the "Text" property of the control.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width