string strConn="联接数据库的字串"
SqlConnection myConnection=new SqlConnection(strConn);
string myFindStr = "select field1,field2 from table1 where ";
myCommand =new SqlCommand(myFindStr, myConnection);
myCommand.CommandTimeout = 30;
myConnection.Open();
SqlDataReader myReader;
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
label1.text= myReader.GetString(0);
label2.text=myReader.GetFloat(1);
}
myReader.Close();
myConnection.Close();
大概就是这样。
SqlConnection myConnection=new SqlConnection(strConn);
string myFindStr = "select field1,field2 from table1 where ";
myCommand =new SqlCommand(myFindStr, myConnection);
myCommand.CommandTimeout = 30;
myConnection.Open();
SqlDataReader myReader;
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
label1.text= myReader.GetString(0);
label2.text=myReader.GetFloat(1);
}
myReader.Close();
myConnection.Close();
大概就是这样。
textBox1.DataBindings.Add(new Binding("Text", dataTable1, "column1"));
如是Lable控件(lable1),方法通上:
lable1.DataBindings.Add(new Binding("Text", dataTable1, "column1"));