Dear sir this is the 1st time i am using forum and i need the code and procedure how to retriving itemname from sql to textbox2 while typing itemno. in textbox1
moreinfo: i am preparing billing system in that when we type product id we will be getting list of products as we go on typing in textbox1 and also its price and and discounts in textbox3 and 4 respectively.
Thanks in advance and help me guys m stuck here from past 4days
Loading
Pravin GhadgePosted Dec 30, 2011, 4:44 AM
private void textbox1_TextChanged(object sender, EventArgs e)
{
SqlConnection con=new SqlConnection();//write ur connection string;
SqlCommand cmd=new SqlCommand("Select Itemname,itemprice ,itemdisc from table where itemno='"+textbox1.Text+"'",con);
con.Open();
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
textbox2.Text=dr[0].Tostring();
textbox3.Text=dr[1].Tostring();
textbox4.Text=dr[2].Tostring();
}
}
Satyapriya NayakPosted Dec 30, 2011, 4:56 AM
private void textbox1_TextChanged(object sender, EventArgs e)
{
con.Open();
str = "select * from student where sid='" + textBox1.Text.Trim() + "'";
com = new SqlCommand(str, con);
SqlDataReader reader=com.ExecuteReader();
if( reader.Read())
{
textBox2.Text = reader["sname"].ToString();
textBox3.Text = reader["smarks"].ToString();
textBox4.Text = reader["saddress"].ToString();
}
con.Close();
reader.Close();
}
Thanks
karthik hPosted Dec 30, 2011, 4:41 AM
i used this code:
SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=pubs");//write ur connection string;
SqlCommand cmd = new SqlCommand("select itemname from bsid where itemno='" + textBox1.Text + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
textBox2.Text = dr[0].ToString();
textBox3.Text = dr[1].ToString();// got error here
textBox4.Text = dr[2].ToString();// got error here
}
Pravin GhadgePosted Dec 30, 2011, 4:21 AM
u have to create event of textbox1
private void textbox1_TextChanged(object sender, EventArgs e)
{
SqlConnection con=new SqlConnection();//write ur connection string;
SqlCommand cmd=new SqlCommand("Select Itemname from table where itemno='"+textbox1.Text+"'",con);
con.Open();
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
textbox2.Text=dr[0].Tostring();
}
}