I need to bind a field(ComputerTag) to a Text field.
This my code:
public void load()
{
//Intializing sql statement
string sqlStatement = "SELECT Computertag FROM Computer WHER
ComputerID=@ComputerID";
SqlCommand comm = new SqlCommand();
comm.CommandText = sqlStatement;
int computerID = int.Parse(Request.QueryString["ComputerID"]);
//get database connection from Ideal_dataAccess class
SqlConnection connection = Ideal_DataAccess.getConnection();
comm.Connection = connection;
comm.Parameters.AddWithValue("@ComputerID", computerID);
try
{
connection.Open();
comm.ExecuteNonQuery();
//Bind the computer tag value to the txtBxCompTag Text box
txtBxCompTag.Text= string.Format("<%# Bind(\"{0}\") %>", "Computertag");
}
catch (Exception ex)
{
Utilities.LogError(ex);
throw ex;
}
finally
{
connection.Close();
}
}
but “txtBxCompTag.Text = string.Format(“<%# Bind(\”{0}\”) %>”, “Computertag”);” this line of code doesn’t bind the value to the text box. How can I assign the value to the text box?
You can use ExecuteReader
Above code comes from msdn: http://msdn.microsoft.com/en-us/library/9kcbe65k(v=vs.90).aspx