SqlConnection cn=new SqlConnection(connectionString); SqlCommand cmd=new SqlCommand("select * from u where *='"+*+"'"); cmd.Connection=cn; DataReader1=cmd.ExecuteReader(); if(DataReader1.Read()) TextBox1.Text=DataReader1[0].ToString(); DataReader1.Close(); connectionString:为数据库的连接字符串; select * from u where *='"+*+"':为查询命令; DataReader1[0].ToString();为需要显示在文本框的字段值,
如果你是绑定到DataGrid,那么,具体的哪一列可以自己控制,也可以由DataGrid自动产生,在自动产生时,列在DataGrid中的列的位置就是相应的你的SQL语句中指定的位置。
SqlCommand cmd=new SqlCommand("select * from u where *='"+*+"'");
cmd.Connection=cn;
DataReader1=cmd.ExecuteReader();
if(DataReader1.Read())
TextBox1.Text=DataReader1[0].ToString();
DataReader1.Close();
connectionString:为数据库的连接字符串;
select * from u where *='"+*+"':为查询命令;
DataReader1[0].ToString();为需要显示在文本框的字段值,
这个[0]表示的是不是第一行第一个列?回复人: helloayu(阿宇) ( ) 信誉:100 2003-11-07 10:15:00 得分:0
这样:先是要把表读入到一个DataSet里面,比如有ds
然后 用TEXTBOX.Text = ds.Table["U"].Row[行号]["列名"].ToString();
用这个方法的时候,程序提示“未将对象引用设置到对象的实例”是怎么回事?string sql="select * from U";
sqladapter sa =new sqladapter (sql,cn);
dataset ds=new dataset();
sa.fill(ds);
TEXTBOX.Text = ds.Table["U"].Row[行号]["列名"].ToString();