我想更新一個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