【发布时间】:2020-09-18 21:34:47
【问题描述】:
请让我解释一下我的 Visual Studio Pro 代码有一些奇怪的地方。没有断开循环的错误消息。似乎我放弃检查我的销售点项目的所有文件有什么问题。所以直到下面的代码工作正常。
private void button1_Click(object sender, EventArgs e)
{
try
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = con;
cmd.CommandText = "Insert into salesproducts(saleid,productname,qty,grosstotal)values(@saleid,@productname,@qty,@grosstotal)";
cmd.Parameters.AddWithValue("@saleid", lbinvoice.Text);
cmd.Parameters.AddWithValue("@productname", dataGridView1.Rows[i].Cells[2].Value);
cmd.Parameters.AddWithValue("@qty", dataGridView1.Rows[i].Cells[3].Value);
cmd.Parameters.AddWithValue("@grosstotal", dataGridView1.Rows[i].Cells[4].Value);
MySqlCommand cmd1 = new MySqlCommand();
cmd1.Connection = con;
cmd1.CommandText = "insert into salesmain(id,date,time,cashername,qty,grosstotal)values(@id,@date,@time,@cashername,@qty,@grosstotal)";
cmd1.Parameters.AddWithValue("@id", lbinvoice.Text);
cmd1.Parameters.AddWithValue("@date", lbldate.Text);
cmd1.Parameters.AddWithValue("@time", lbltime.Text);
cmd1.Parameters.AddWithValue("@cashername", label6.Text);
cmd1.Parameters.AddWithValue("@qty", lbitems.Text);
cmd1.Parameters.AddWithValue("@grosstotal", lbtotal.Text);
con.Open();
int x = cmd.ExecuteNonQuery();
int y = cmd1.ExecuteNonQuery();
MessageBox.Show("Record added ..........");
updatedb();
}
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
// everything worked fine of project till now......
但是在添加这些代码之后 像现在这样然后没有任何效果。
updatedb();
//Nothing worked from here...
dataGridView1.Rows.Clear();
lbtotal.Text = "0";
lbitems.Text = "0";
txtno.Focus();
totalPrice = 0;
con.Close();
invoice();
}
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
对不起,我无法完整显示图片截图或者这里没有任何权限。请点击以下链接。
Please watch the sales window here
then please watch this one to know whats not work
我希望在不添加额外文件代码的情况下找到解决方案。谢谢
【问题讨论】:
-
在 catch 处设置断点或者去掉 try catch 看看有没有异常!
-
我试图在我的测试中重现该问题,但一切正常。所有的控制都可以重置。我注意到您调用了方法
updatedb()和invoice()。能否提供这些方法的具体代码?最好能提供一个简单的demo,能复现遇到的问题。 -
我添加了其他信息,请在下面查看。
标签: c# .net visual-studio