Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Somebody please help. I'm creating a cash memo in table format with 6 rows and 5 columns with multiple textboxes. So I need to autofill remaining textboxes after I enter value in 1 textbox, similarly the remaining.

I'm posting code here.
C#
try
{
    AutoCompleteStringCollection namescolln = new AutoCompleteStringCollection();
    SqlConnection myconn = new SqlConnection("Data Source=ACER-PC\\SQLEXPRESS;Initial Catalog=CSM;Integrated Security=True");
    myconn.Open();
    SqlCommand cmnd = myconn.CreateCommand();
    DataTable dt = new DataTable();

    SqlDataAdapter sda0 = new SqlDataAdapter("select * from dbo.bill where prod_id='" + this.textBox2.Text + "';", myconn);

    sda0.Fill(dt);
    textBox1.Text = dt.Rows[0].ItemArray[1].ToString();
    textBox3.Text = dt.Rows[0].ItemArray[2].ToString();
    textBox4.Text = dt.Rows[0].ItemArray[3].ToString();
    textBox5.Text = dt.Rows[0].ItemArray[4].ToString();
    textBox6.Text = dt.Rows[0].ItemArray[5].ToString();

    SqlDataAdapter sda1 = new SqlDataAdapter("select * from dbo.bill where prod_id='" + this.textBox7.Text + "';", myconn);
    sda1.Fill(dt);
    textBox8.Text = dt.Rows[1].ItemArray[1].ToString();
    textBox9.Text = dt.Rows[1].ItemArray[2].ToString();
    textBox10.Text = dt.Rows[1].ItemArray[3].ToString();
    textBox11.Text = dt.Rows[1].ItemArray[4].ToString();
    textBox12.Text = dt.Rows[1].ItemArray[5].ToString();

    SqlDataAdapter sda2 = new SqlDataAdapter("select * from dbo.bill where prod_id='" + this.textBox13.Text + "';", myconn);
    sda2.Fill(dt);
    textBox14.Text = dt.Rows[2].ItemArray[1].ToString();
    textBox15.Text = dt.Rows[2].ItemArray[2].ToString();
    textBox16.Text = dt.Rows[2].ItemArray[3].ToString();
    textBox17.Text = dt.Rows[2].ItemArray[4].ToString();
    textBox18.Text = dt.Rows[2].ItemArray[5].ToString();

    SqlDataAdapter sda3 = new SqlDataAdapter("select * from dbo.bill where prod_id='" + this.textBox19.Text + "';", myconn);
    sda3.Fill(dt);
    textBox20.Text = dt.Rows[3].ItemArray[1].ToString();
    textBox21.Text = dt.Rows[3].ItemArray[2].ToString();
    textBox22.Text = dt.Rows[3].ItemArray[3].ToString();
    textBox23.Text = dt.Rows[3].ItemArray[4].ToString();
    textBox24.Text = dt.Rows[3].ItemArray[5].ToString();

    SqlDataAdapter sda4 = new SqlDataAdapter("select * from dbo.bill where prod_id='" + this.textBox31.Text + "';", myconn);
    sda4.Fill(dt);
    textBox32.Text = dt.Rows[4].ItemArray[1].ToString();
    textBox33.Text = dt.Rows[4].ItemArray[2].ToString();
    textBox34.Text = dt.Rows[4].ItemArray[3].ToString();
    textBox35.Text = dt.Rows[4].ItemArray[4].ToString();
    textBox36.Text = dt.Rows[4].ItemArray[5].ToString();

    

    myconn.Close();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}

Please Help.
Posted
v2
Comments
So where is the issue? Any exception?
Vinod P 3-Oct-15 6:06am    
Hi,
I was able to autofill the first row when id was entered in textbox.
But was not able to autofill the second and third rows with the above code.
Please help
What is the issue? Did you debug and see the values? Is there any exception?
Vinod P 3-Oct-15 23:24pm    
Hi friends,

Got the solution for the problem. My mistake. I didnt place second row inside the next textbox_changed event.So it was checking the row in db for the content which was not present.

Thanks for all your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900