如何将数据库中的数据取到TextBox中?在线等待!
用选择查询语句:select name from Employee where id=001。
我想将取到的name值放到TextBox中,或者说我如何得到从数据库中返回的值?怎么实现?
是不是有点弱?不好意思!
先谢谢大家了。
问题点数:50、回复次数:9Top
1 楼cnhgj(戏子) (没时间练太极)回复于 2004-11-03 12:03:41 得分 35
SqlDataAdapter adp = new SqlAdapter("select [name] from Employee where id=001", Conn);
DataSet dt = new DataSet();
adp.Fill(dt, "Employee");
if (dt.Tables["Employee"].Rows.Count > 0)
{
textBox1.Text = dt.Tables["Employee"].Rows[0]["name"].ToString();
}
dt.Tables["Employee"].Clear();Top
2 楼boytomato(深爱一人叫颖的女孩!)回复于 2004-11-03 12:05:03 得分 5
System.Data.OleDb.OleDbDataAdapter odd=new OleDbDataAdapter("select name from Employee where id=001 ",this.cnn);
DataTable table=new DataTable();
odd.Fill(table);
this.TextBox1.text=table.Rows[0][0].ToString();Top
3 楼ml_tt(梵笙)回复于 2004-11-03 12:12:28 得分 0
谢谢!先让我试试先!Top
4 楼mbh0210(独孤求败)回复于 2004-11-03 12:16:15 得分 5
楼上的可以
取出数值赋值久可以了.Top
5 楼lifeixie(lifeixie)回复于 2004-11-03 12:31:02 得分 5
mycon = new OleDbConnection(cnn);
mycon.Open();
OleDbCommand command = mycon.CreateCommand(); //创建Command对象
command.CommandText = "Select * From terminal where terminal_name = '"+strID+"'";
OleDbDataReader myReader = command.ExecuteReader();
myReader.Read();
this.txtName.Text = myReader.GetString(2); //名称
this.txtId.Text = myReader.GetString(0);
this.txtAddress.Text = myReader.GetString(1);
this.cbozt.Text = myReader.GetString(23);
this.dateTimePicker.Text = myReader.GetString(12);
this.txtFalg1.Text = myReader.GetByte(21).ToString();
this.txtFalg2.Text = myReader.GetByte(22).ToString();
this.txtAVA.Text = myReader.GetString(5);
this.txtBVA.Text = myReader.GetString(6);
this.txtCVA.Text = myReader.GetString(7);
this.txtAVI.Text = myReader.GetString(8);
this.txtBVI.Text = myReader.GetString(9);
this.txtCVI.Text = myReader.GetString(10);Top
6 楼ml_tt(梵笙)回复于 2004-11-03 12:51:00 得分 0
已经解决了,谢谢!
还想再问一下,我想将TextBox1中的值与TextBox2中的值相乘后把值赋给TextBox3,又该如何做?Top
7 楼ml_tt(梵笙)回复于 2004-11-03 12:53:57 得分 0
我是这样做的。
TextBox3.text=Convert.tostring(Convert.toDecimal(TextBox1.text)*Convert.toDecimal(TextBox2.text));
我这样等到的是错误的,请问我错在哪儿?
应该怎么改?
谢谢!!Top
8 楼zse3(吴琳)回复于 2004-11-03 13:15:06 得分 0
你用deciaml.para...进行转化!然后进行操作。再赋给TextBox3Top
9 楼ml_tt(梵笙)回复于 2004-11-03 13:47:48 得分 0
zse3(吴琳)
谢谢!
可以再讲详细一点吗?Top




