我想更新一个c#for循环内的mysql表和if语句以及几个if语句。当运行一个中断点时,它将运行一次执行查询,但下一次循环不会执行该命令。即使当我打非查询它不会改变表信息。更新表里面for循环
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将每次运行 谢谢你看,你的帮助 更新字符串看起来像 “更新spt_results SET FFI 300 = '15',其中PROJECT_ID = AAA007”,当它刚刚connection2.Open();
后运行
布伦特
谢谢移动打开的连接并更改字符串的工作很好我一直在玩的MyphpAdmin的SQL,发现我不得不引用FFI,但似乎无法得到它的权利再次谢谢 – bmorrison1982