C#在获取时有一些错误

时间:2011-06-16 16:05:25

标签: c#

 private void TxtFarmerCode_TextChanged(object sender, EventArgs e)
       {
             try
            {
                cmd.Open();
                cmd = new SqlCommand("Select farmername, from cottonpurchase where farmercode=@aa", conn);
                cmd.Parameters.Add("@aa", SqlDbType.Int).Value = TxtFarmerCode.Text;
                dr = cmd.ExecuteReader();
                if (dr.HasRows == false)
                {
                    throw new Exception();
                }
                if (dr.Read())
                {
                    // textBox1.Text = dr[0].ToString(); Since U r going to give the ID and retrieve in textBox1.
                    TxtFarmerName.Text = dr[0].ToString();
                    //textBox3.Text = dr[1].ToString();
                    //textBox4.Text = dr[2].ToString();
                    //textBox7.Text = dr[3].ToString();
                    //dateTimePicker1.Text = dr[4].ToString();
                    //dateTimePicker2.Text = dr[5].ToString();
                    //textBox5.Text = dr[6].ToString();
                }
            }
            catch
            {
            //    lblError = "THE GIVEN ID IS UNAVAILABLE";
            }
            finally
            {
                conn.Close();
            }

1 个答案:

答案 0 :(得分:0)