TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
varsha dodiya
NA
407
75.4k
problem in text change event of combobox
Jul 11 2014 5:26 AM
I have two combobox comboboxP (fetch products name) and comboboxB (fetch Batchno) . I put code in comboboxP textchanged event to fetch data in comboboxB and other textboxes . when i select any value in comboboxB its related textboxes and comboboxP also should b filled with related values.this is my code for comboboxP in which you can see comboboxB is getting value on changing comboboxP's text.
private void comboProname_TextChanged(object sender, EventArgs e)
{
cmd = new SqlCommand("select P_batchno,P_min_stk,P_max_stk,P_vat from PRO where P_name='" + comboProname.Text + "'", conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
AutoCompleteStringCollection MyCollection7 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection9 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection10 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection11 = new AutoCompleteStringCollection();
while (reader.Read())
{
MyCollection7.Add(reader["P_batchno"].ToString());
MyCollection9.Add(reader["P_max_stk"].ToString());
MyCollection10.Add(reader["P_min_stk"].ToString());
MyCollection11.Add(reader["P_vat"].ToString());
comboBthNo.Items.Add(reader["P_batchno"].ToString());
tbMaxStk.Text = (reader["P_max_stk"].ToString());
tbMinstk.Text = (reader["P_min_stk"].ToString());
tbVAT.Text = (reader["P_vat"].ToString());
}
comboBthNo.AutoCompleteCustomSource = MyCollection7;
tbMaxStk.AutoCompleteCustomSource = MyCollection9;
tbMinstk.AutoCompleteCustomSource = MyCollection10;
tbVAT.AutoCompleteCustomSource = MyCollection11;
conn.Close();
}
// now see code for comboboxB's text change in dis comboboxP's value is changed
private void comboBthNo_TextChanged(object sender, EventArgs e)
{
cmd = new SqlCommand("SELECT P_name,P_pack,P_comp,P_rate,P_mrp from PRO where P_batchno='" + comboBthNo.Text + "'", conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
AutoCompleteStringCollection MyCollection5 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection6 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection8 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection12 = new AutoCompleteStringCollection();
AutoCompleteStringCollection MyCollection13 = new AutoCompleteStringCollection();
while (reader.Read())
{
MyCollection5.Add(reader["P_name"].ToString());
MyCollection6.Add(reader["P_comp"].ToString());
MyCollection8.Add(reader["P_pack"].ToString());
MyCollection12.Add(reader["P_rate"].ToString());
MyCollection13.Add(reader["P_mrp"].ToString());
comboProname.Text = reader["P_name"].ToString();
tbPAck.Text = (reader["P_pack"].ToString());
tbCmpName.Text = (reader["P_comp"].ToString());
tbRate.Text = (reader["P_rate"].ToString());
tbMrp.Text = (reader["P_mrp"].ToString());
}
comboProname.AutoCompleteCustomSource = MyCollection5;
tbPAck.AutoCompleteCustomSource = MyCollection6;
tbCmpName.AutoCompleteCustomSource = MyCollection8;
tbRate.AutoCompleteCustomSource = MyCollection12;
tbMrp.AutoCompleteCustomSource = MyCollection13;
conn.Close();
}
it is trowing exception another reader is already attached to it is open... someting like this .. help me in fixing it
Reply
Answers (
2
)
display a dataBase Table in my multiple column comboBox
Disabling the screenshot facility in Windows Phone app