我正在尝试在 ac# for 循环和 if 语句以及一些 if 语句中更新 mysql 表。在使用断点运行时,它将运行 executenonquery 一次,但在下一个循环中它不会命中。即使我确实点击了非查询,它也不会更改表信息。
ffi 字符串是我表中列的名称,字符串 val 是我要输入的内容。我知道这不是安全的方法,但是当我可以让它按应有的方式工作时,我会更改它。更新了代码,它现在每次应该运行 NONQUERY,但仍然没有更新表代码:
for (a = 0; a <= z; a++)
{
if (ds3.Tables[0].Rows[a][1].ToString() == dataGridView1.Rows[i].Cells[0].Value.ToString())
{
if (ds3.Tables[0].Rows[a][2].ToString() == dataGridView1.Rows[i].Cells[1].Value.ToString())
{
if (ds3.Tables[0].Rows[a][3].ToString() == dataGridView1.Rows[i].Cells[2].Value.ToString())
{
MessageBox.Show("We have a match " + dataGridView1.Rows[i].Cells[0].Value.ToString() + " " + dataGridView1.Rows[i].Cells[1].Value.ToString() + " " + dataGridView1.Rows[i].Cells[t].Value.ToString());
try
{
string ffi = textBox1.Text;
decimal val = decimal.Parse(dataGridView1.Rows[i].Cells[t].Value.ToString());
MySqlCommand cmd = new MySqlCommand("Update spt_results SET " + ffi + " = " + val + " where project_Id =" + dataGridView1.Rows[i].Cells[0].Value.ToString() + "",connection2);
//cmd.Connection = connection2;'
// cmd.Connection.Open();
cmd.ExecuteNonQuery();
//cmd.Connection.Close();
}
catch
{
}
消息框确实显示每个循环,connection2.open 每次都会运行 感谢您的查看和您的帮助 更新字符串在运行时看起来像“update spt_results SET FFI 300 = '15' where project_Id =AAA007”
布伦特