当前位置:编程学习 > C#/ASP.NET >>

textBox查询结果显示的问题

我有一张表,里面3个字段,name,address,age; 
在winform中做了3个textbox,在txtName中输入name,在txtAddress和txtAge中把查询的结果显示出来。 
不知道怎么写,能帮忙写个简单的例子吗?还有如果通过SqlHepler来做这个功能的话,该怎么写? 
把查询的结果输出的DataGirdView中很好做,但是突然要显示在textBox中不知道怎么下手了。希望大家帮帮忙,谢过 --------------------编程问答-------------------- 这不很简单吗

using(SqlConnection conn = new SqlConnection("连接字符串"))
{
    SqlCommand cmd = new SqlCommand("select * from yourtable where name ='" + txtName.Text + "'",conn);
    using(SqlDataReader sdr = cmd.ExecuteReader())
    {
         if(sdr.Read())
         {
              txtAddress.Text = sdr["address"].ToString();
              txtAge.Text = sdr["age"].ToString(); 
         }
    }
}
--------------------编程问答-------------------- this.textBox.Text=你绑定的值。 --------------------编程问答-------------------- select adddress,age from Table where name = '"+txtname+"' --------------------编程问答--------------------
引用 3 楼 lsj47987850 的回复:
select adddress,age from Table where name = '"+txtname+"'


请问里面的+号是什么意思? --------------------编程问答-------------------- 字符串连接
--------------------编程问答-------------------- private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode==Keys.Enter)
{
e.Handled=true;
this.textBox2.Focus();
}
}

private void textBox1_Leave(object sender, System.EventArgs e)
{
string strCn="User ID=sa;Initial Catalog=ha;Data Source=0000";
SqlConnection con=new SqlConnection(strCn);
con.Open();
string strSql="select * from TMC_Member where EmployeeNo='"+this.textBox1.Text+"'";
SqlCommand cmd=new SqlCommand(strSql,con);
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
this.textBox2.Text=dr["EmployeeName"].ToString();
this.textBox3.Text=dr["Password"].ToString();
}
dr.Close();
con.Close();

}
--------------------编程问答-------------------- 看看  吧 这个我执行过了
--------------------编程问答-------------------- using(SqlConnection conn = new SqlConnection("连接字符串"))
{
    SqlCommand cmd = new SqlCommand("select * from yourtable where name ='" + txtName.Text + "'",conn);
    using(SqlDataReader sdr = cmd.ExecuteReader())
    {
         if(sdr.Read())
         {
              txtAddress.Text = sdr["address"].ToString();
              txtAge.Text = sdr["age"].ToString(); 
         }
    }
}
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,