1。怎样从一个textBox1输入UserID,通过数据库在textBox2中显示出UserName
2。

解决方案 »

  1.   

    这是最基本的查询啊string sql = "select UserName from table1 where UserID="+textBox1.Text;
    SqlConnection conn = new SqlConnection(sConn);
    conn.Open();
    SqlCommand cmd = new SqlCommand(sql, conn);
    textBox2.Text = cmd.ExecuteScalar().ToString();
    cmd.Dispose();
    conn.Close();
      

  2.   

    把textBox1的值作为sql语句where子句的条件,查询数据库,把结果绑定到textBox2
      

  3.   

    在textBox1的keypress或可以down中判断,if是enter键,根据userId查询相应的username,
    然后textBox2.text=usernmae;
      

  4.   

    private void textBox1_Validated(object sender, EventArgs e)
            {
                if (txtRWellGuid.Text.Trim() != "" || txtRWellGuid.Text.Trim() != string.Empty)
                {
                    string sql = "select UserName from table1 where UserID="+textBox1.Text;
    string sConn=""//你的连接字符串
    SqlConnection conn = new SqlConnection(sConn);
    conn.Open();
    SqlCommand cmd = new SqlCommand(sql, conn);
    textBox2.Text = cmd.ExecuteScalar().ToString();
    cmd.Dispose();
    conn.Close();            }
            }
      

  5.   

    很简单的, 
    string sql = "select UserName from table1 where UserID="+textBox1.Text;  // 这个是SQL语句
    SqlConnection conn = new SqlConnection(sConn);  // sConn 是数据库联接字符串 自己去写
    conn.Open();  // 打开操作
    SqlCommand cmd = new SqlCommand(sql, conn);  // 执行SQL语句
    textBox2.Text = cmd.ExecuteScalar().ToString();  
    cmd.Dispose();
    conn.Close();
      

  6.   

    这应该是比较基础的东西
    string sql = "select UserName from table1 where UserID="+textBox1.Text;  // 这个是SQL语句
    SqlConnection conn = new SqlConnection(sConn);  // sConn 是数据库联接字符串 自己去写
    conn.Open();  // 打开操作
    SqlCommand cmd = new SqlCommand(sql, conn);  // 执行SQL语句
    textBox2.Text = cmd.ExecuteScalar().ToString();  
    cmd.Dispose();
    conn.Close();
      

  7.   

    //读取web.config数据库连接参数
    string StrConn= ConfigurationSettings.AppSettings["ConnectionStr"];
    //
    string Sql = "select UserName from table1 where UserID="+textBox1.Text;
    SqlConnection Conn = new SqlConnection(StrConn);
    Conn.Open();
    SqlCommand Cmd = new SqlCommand(Sql, conn);
    textBox2.Text = Cmd.ExecuteScalar().ToString();
    Cmd.Dispose();
    Conn.Close();
      

  8.   

    viena(维也纳N02) ( 三星(高级)) 
    你也是三星用户了,别教坏小孩子
    以后别教人写这样代码
    string sql = "select UserName from table1 where UserID="+textBox1.Text;
      

  9.   

    LZ可能不是大家说的意思.将textBox1的AutoPostBack属性设置为true.
    protected void txt_textBox1_TextChanged(object sender, EventArgs e)
    {
    //dosomething
    }
      

  10.   

    viena(维也纳N02) zheng jie
      

  11.   

    1楼的只为抢分,没有专业精神
    string sql = "select UserName from table1 where UserID="+textBox1.Text;
    这样的代码也写
      

  12.   

    我估计楼主想问2级联动(和数据库关联)怎么做?
    我是通过jsp和javascript来做的
      

  13.   

    这个问题用到的就是一句SELECT
    把TEXTBOX1的内容做WHERE条件
    把TEXTBOX2需要的内容做SELECT后面的字段名1LZ看看SQL方面的知识吧,不管以后搞什么,SQL语句都用得上
    2有兴趣看点ADO。NET方面的书
    3不管FORM,还是WEB,找书了解下控件,再学习一种语言最后,LZ加油,刚开始都是这样的。建议你有问题多问你身边的人,他们会乐于帮你的,
    只要你虚心点,有点眼色(不要别人真忙着时候不停的问)
      

  14.   

    建议LZ认真看下ADO.NET的知识!!
      

  15.   

    把textBox1的值作为sql语句where子句的条件,查询数据库,把结果绑定到textBox2
      

  16.   

    我感觉楼主的意思是让动态显示的 ,这样的话就用AJAX
      

  17.   

    zhe yang xie tai weiqian