textbox1中输入的是id值,id是数据库中的列名,是主键,我想实现的是其余的textbox自动显示该id所在行的其余的数据,

解决方案 »

  1.   

    你在数据库中查询出textbox1中id所在数据行
    然后逐个将数据绑定到其它textbox不就行了
      

  2.   

    那你就在输入ID的后根据文本框的ID 把这条数据查出来不就行了
      

  3.   

        string str = "select chezhuxingming,chexing,fadongjihao,vinhao,chejiahao,goucheriqi,xinchegoujia from baoxianxinxi where chepaihao ='" + textBox1.Text + "'";
                SqlConnection sqlcon = new SqlConnection("server=.;uid=sa;pwd=sa;DataBase=me");
                sqlcon.Open();
                SqlDataAdapter myda = new SqlDataAdapter(str, sqlcon);
                DataSet myds = new DataSet();
                myda.Fill(myds, "baoxianguanli");
                 
                    textBox2.Text = myds.Tables[0].Rows[0]["chezhuxingming"].ToString();
                    textBox3.Text = myds.Tables[0].Rows[0]["chexing"].ToString();
                    textBox4.Text = myds.Tables[0].Rows[0]["fadongjihao"].ToString();
                    textBox5.Text = myds.Tables[0].Rows[0]["vinhao"].ToString();
                    textBox6.Text = myds.Tables[0].Rows[0]["chejiahao"].ToString();
                    textBox8.Text = myds.Tables[0].Rows[0]["goucheriqi"].ToString();
                    textBox9.Text = myds.Tables[0].Rows[0]["xinchegoujia"].ToString();
                
                sqlcon.Close();上面是我写的代码,不知道查询语句对不对,提示的错误是: textBox2.Text = myds.Tables[0].Rows[0]["chezhuxingming"].ToString()在位置0处没有任何行
      

  4.   

    高手帮看看,怎样修改?chepaihao就是我所说的id,谢谢!
      

  5.   

     textBox2.Text = myds.Tables[0].Rows[0]["chezhuxingming"].ToString(); 
     Rows[0]["chezhuxingming"] []这里放的应该是列名或是列索引值
      

  6.   

    调试,看有没有查到数据,看SQL 是否正确
      

  7.   

    这个语句没有错误,不过缺少一个判断,当表中没有数据时就会这样提示在位置0处没有任何行 
    。可以改过:
     if (myds  != null && myds.Tables[0].Rows.Count > 0)
            {
                 textBox2.Text = myds.Tables[0].Rows[0]["chezhuxingming"].ToString(); 
                    textBox3.Text = myds.Tables[0].Rows[0]["chexing"].ToString(); 
                    textBox4.Text = myds.Tables[0].Rows[0]["fadongjihao"].ToString(); 
                    textBox5.Text = myds.Tables[0].Rows[0]["vinhao"].ToString(); 
                    textBox6.Text = myds.Tables[0].Rows[0]["chejiahao"].ToString(); 
                    textBox8.Text = myds.Tables[0].Rows[0]["goucheriqi"].ToString(); 
                    textBox9.Text = myds.Tables[0].Rows[0]["xinchegoujia"].ToString();         }
      

  8.   

    加个判断
      string str = "select chezhuxingming,chexing,fadongjihao,vinhao,chejiahao,goucheriqi,xinchegoujia from baoxianxinxi where chepaihao ='" + textBox1.Text + "'"; 
                SqlConnection sqlcon = new SqlConnection("server=.;uid=sa;pwd=sa;DataBase=me"); 
                sqlcon.Open(); 
                SqlDataAdapter myda = new SqlDataAdapter(str, sqlcon); 
                DataSet myds = new DataSet(); 
                DataTable dt= myda.Fill(myds, "baoxianguanli");
                
                if(dt!=null)
                {
                    textBox2.Text = dt.Rows[0]["chezhuxingming"].ToString(); 
                    textBox3.Text = dt.Rows[0]["chexing"].ToString(); 
                    textBox4.Text = dt.Rows[0]["fadongjihao"].ToString(); 
                    textBox5.Text = dt.Rows[0]["vinhao"].ToString(); 
                    textBox6.Text = dt.Rows[0]["chejiahao"].ToString(); 
                    textBox8.Text = dt.Rows[0]["goucheriqi"].ToString(); 
                    textBox9.Text = myds.Tables[0].Rows[0]["xinchegoujia"].ToString(); 
                 }
      

  9.   

    加个判断 
      string str = "select chezhuxingming,chexing,fadongjihao,vinhao,chejiahao,goucheriqi,xinchegoujia from baoxianxinxi where chepaihao ='" + textBox1.Text + "'"; 
                SqlConnection sqlcon = new SqlConnection("server=.;uid=sa;pwd=sa;DataBase=me"); 
                sqlcon.Open(); 
                SqlDataAdapter myda = new SqlDataAdapter(str, sqlcon); 
                DataSet myds = new DataSet(); 
                DataTable dt= myda.Fill(myds, "baoxianguanli"); 
                
                if(dt!=null && dt.Rows.Count>0) 
                { 
                    textBox2.Text = dt.Rows[0]["chezhuxingming"].ToString(); 
                    textBox3.Text = dt.Rows[0]["chexing"].ToString(); 
                    textBox4.Text = dt.Rows[0]["fadongjihao"].ToString(); 
                    textBox5.Text = dt.Rows[0]["vinhao"].ToString(); 
                    textBox6.Text = dt.Rows[0]["chejiahao"].ToString(); 
                    textBox8.Text = dt.Rows[0]["goucheriqi"].ToString(); 
                    textBox9.Text = myds.Tables[0].Rows[0]["xinchegoujia"].ToString(); 
                } 
      

  10.   

    你的数据库中没有这条记录,你可以先判断一下
    if(myds.Tables[0].Rows.Count>0)
    {
    //写你原来的代码
    }