public void procate()
{
// PrintDB pdb = new PrintDB();
MySqlConnection con = pdb.Creation();
con.Open();
MySqlCommand com = new MySqlCommand("select categroy from proprice where type='" + listBox1.Text + "' group by categroy", con);
MySqlDataReader da = com.ExecuteReader();
if (listBox2.Items.Count > 0)
{
listBox2.Items.Clear();
}
if (da.HasRows)
{
while (da.Read())
{
listBox2.Items.Add(da["categroy"].ToString());
}
listBox2.SelectedIndex = 0;//输入字符串格式不正确
}
else
{
listBox2.Items.Add("0");
}
da.Dispose();
da.Close();
con.Dispose();
con.Close();
}
/// <summary>
/// 获取产品样式列表
/// </summary>
public void prostyle()
{
MySqlConnection con = pdb.Creation();
con.Open();
MySqlCommand com = new MySqlCommand("select style from proprice where categroy='" + listBox2.Text + "' group by style", con);
MySqlDataReader da = com.ExecuteReader();
if (listBox3.Items.Count > 0)
{
listBox3.Items.Clear();
}
if (da.HasRows)
{
while (da.Read())
{
listBox3.Items.Add(da["style"].ToString());
}
listBox3.SelectedIndex = 0;
}
else
{
listBox3.Items.Add("0");
}
da.Dispose();
da.Close();
con.Dispose();
con.Close();
}
/// <summary>
/// 获取产品数量
/// </summary>
public void proqty()
{
// listBox4.Items.Clear();
MySqlConnection con = pdb.Creation();
con.Open();
MySqlCommand com = new MySqlCommand("select qty from proprice where categroy='"+listBox2.Text+"' and style='" + listBox3.Text + "' group by qty", con);
MySqlDataReader da = com.ExecuteReader();
if (listBox4.Items.Count > 0)
{
listBox4.Items.Clear();
}
if (da.HasRows)
{
while (da.Read())
{
listBox4.Items.Add(da["qty"].ToString());
}
listBox4.SelectedIndex = 0;
}
else
{
listBox4.Items.Add("0");
}
da.Dispose();
da.Close();
con.Dispose();
con.Close();
}
/// <summary>
/// 获取产品规格
/// </summary>
public void prounit()
{
//listBox5.Items.Clear();
MySqlConnection con = pdb.Creation();
con.Open();
MySqlCommand com = new MySqlCommand("select unit from proprice where categroy='"+listBox2.Text+"' and style='" + listBox3.Text + "' group by unit", con);
MySqlDataReader da = com.ExecuteReader();
//listBox5.Items.Clear();
if (listBox5.Items.Count > 0)
{
listBox5.Items.Clear();
}
if (da.HasRows)
{
while (da.Read())
{
listBox5.Items.Add(da["unit"].ToString());
}
listBox5.SelectedIndex =0;
}
else
{
listBox5.Items.Add("0");
}
da.Dispose();
da.Close();
con.Dispose();
con.Close();
}
我这样试了的:
listBox1.Items.Add("w");
listBox1.Items.Add("w");
listBox1.Items.Add("w");
listBox1.Items.Add("w");
listBox1.Items.Add("w");
listBox1.SelectedIndex = 0;没有错啊。
你看一下是否是读取数据库的值得方法有错。
while (da.Read())
{
listBox2.Items.Add(da["categroy"].ToString());
//断点下这里,看看da["categroy"].ToString()的值
}