例如表的结构是这样,就2条数据name  address
aa      12
bb      34如果我只想把“aa”这条数据取出来,把他赋给TextBox,应该怎样取实现?我是这样写的,不过不行
int i=1;
TextBox.text=ds.Tables[0].Rows[i]["Name"].ToString();

解决方案 »

  1.   

    select address from 表名 where name='aa'
      

  2.   

    SQLCommand cmd = new SQLCommand("select address from 表名 where name='aa'");
    textBox1.text = Convert.ToString(cmd.ExecuteScalar());
      

  3.   

    SQLCommand cmd = new SQLCommand("select address from 表名 where name='aa'",conn);
    textBox1.text = Convert.ToString(cmd.ExecuteScalar());
      

  4.   

    TextBox.text=ds.Tables[0].Rows[0][0].ToString();
      

  5.   

    SELECT TOP 1 name, address FROM tableName WHERE name = 'aa'
      

  6.   

    TO 
    我是这样写的,不过不行
    int i=1;
    TextBox.text=ds.Tables[0].Rows[i]["Name"].ToString();你要取的是第一行,应该用0来标识

    if(ds.Tables[0].Rows.Count>0)
    {
      TextBox.text=ds.Tables[0].Rows[0]["Name"].ToString();}