输入ID号点查询在文本框中显示ID号对应的其它信息如姓名、性别等
请给出相应语句 在线急等 谢谢各位

解决方案 »

  1.   

    直接查
    Select * from TableName 
    左连接
    Select a.*,b.* from TableName1 a left join TableName2 on a.ID=b.id
      

  2.   

    Select * from 你的表 where id="传来的id"
      

  3.   

    "select * from table where id="+txtid.Text
      

  4.   

    不好意思是我讲的不明白 
    在TextBox1中输入ID号单击按钮进行查询在TextBox2中显示姓名这一列的值
    string selsql="select * from TABLE1 where id='"+this.textBox1.Text.ToString()+"'";
    System.Data.SqlClient.SqlCommand com=new System.Data.SqlClient.SqlCommand(selsql,sqlConnection1);
    this.sqlConnection1.Open();
    this.sqlDataAdapter1.Fill(this.dataSet11,"com");
    this.dataSet11.Tables["Table1"].Rows[1].ItemArray[0].ToString();
    com.ExecuteNonQuery(); 错误提示:在位置1处没有任何行
      

  5.   

            string strGoodsInfo = string.Format("SELECT GoodsId,GoodsName,Amount,Price,Stock FROM tb_GoodsInfo WHERE GoodsId='" + tbx货号.Text.Trim() + "'");
                    DataSet dsGoods = sql_class.GetDs(strGoodsInfo);
                    DataTable dtGoods = dsGoods.Tables[0];                //货号若存在, 就绑定相关控件的数据
                    if (dsGoods.Tables[0].Rows.Count > 0)
                    {
                        lbl品名.Text = "品名:  " + dtGoods.Rows[0]["GoodsName"].ToString();
                        lbl库存.Text = "库存量 :" + dtGoods.Rows[0]["Stock"].ToString();
                    }
    参考一下这个 
      

  6.   


    string strSql = "Select * from Table where id="传来的id";
    DataTable dt = creatDataTable(strSql);
    foreach(DataRow dr in dt.Rows)
    {
        thi.TextBox.Text = dr["你要显示的字段"].Tostring();
    }
      

  7.   

    string ConnStr=ConfigurationSettings.AppSettings["DBConnectionSql"].ToString();
    SqlConnection Sql=new SqlConnection(ConnStr);
    SqlCommand cmd=new SqlCommand("RestoreDb",Sql);
    string Str="select * from A where ID='"+this.txt1.Text+"'";
    Sql.Open();
    cmd.Connection = Sql;
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = Str;
    try
    {
                SqlDataReader dr= cmd.ExecuteReader();
                                        if (dr.Read())
                                        {                                    }
    cmd.Dispose();
    Sql.Close();
    }
    catch(Exception ex)
    {
    cmd.Dispose();
    Sql.Close();
    return;
                                  } }
      

  8.   

    在Select查询语句中最好不要用*号!!!
    最好把你查询的字段写出来!!
      

  9.   

    select 你要得到字段 form 你的表明 where 你的条件!!!
      

  10.   

    传入的ID尾部有空格吧,既然用ID列,干嘛不使用INT类型呢?用字符串最好检查下你传入的字符串长度是否和数据库中的相同,如果长度都不同,怎么可能相等呢?
      

  11.   

    string selsql="select * from TABLE1 where id='"+this.textBox1.Text.Trim()+"'";//ToString改成Trim 
    System.Data.SqlClient.SqlCommand com=new System.Data.SqlClient.SqlCommand(selsql,sqlConnection1); 
    //this.sqlConnection1.Open(); //这句不要
    this.sqlDataAdapter1.Fill(this.dataSet11,"Table1");//com改成Table1 
    //取值前先要判断dataSet11会不会是空的
    if(dataSet11.Tables["Table1"].Rows.Count > 0)
     this.textBox2.Text=this.dataSet11.Tables["Table1"].Rows[0][1].ToString(); //注意这句的Rows[0][1]
    //com.ExecuteNonQuery();// 这句也不要
      

  12.   

    //上面漏改了一句
    string selsql="select * from TABLE1 where id='"+this.textBox1.Text.Trim()+"'";//ToString改成Trim 
    //System.Data.SqlClient.SqlCommand com=new System.Data.SqlClient.SqlCommand(selsql,sqlConnection1); //这句去掉,改成下面这一句:
    sqlDataAdapter1=new System.Data.SqlClient.SqlDataAdapter(selsql,sqlConnection1)
    //this.sqlConnection1.Open(); //这句不要
    this.sqlDataAdapter1.Fill(this.dataSet11,"Table1");//com改成Table1 
    //取值前先要判断dataSet11会不会是空的
    if(dataSet11.Tables["Table1"].Rows.Count > 0)
     this.textBox2.Text=this.dataSet11.Tables["Table1"].Rows[0][1].ToString(); //注意这句的Rows[0][1]
    //com.ExecuteNonQuery();// 这句也不要