[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?
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:
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.