这是我的代码:问题与Windows更新功能形成
private void button3_Click(object sender, EventArgs e)
{
int i;
i = dataGridView1.SelectedCells[0].RowIndex;
textBox1.Text = dataGridView1.Rows[i].Cells[0].Value.ToString();
textBox2.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
textBox3.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Dido\documents\visual studio 2012\Projects\CourseProjectCars\CourseProjectCars\DataCars.mdf;Integrated Security=True;Connect Timeout=30");
con.Open();
SqlCommand cmd = new SqlCommand("Update SuperCars set [email protected],[email protected],[email protected] Where([email protected])", con);
cmd.Parameters.AddWithValue("@Car", textBox1.Text);
cmd.Parameters.AddWithValue("@mph", textBox2.Text);
cmd.Parameters.AddWithValue("@price", textBox3.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("updated......");
con.Close();
Bind();
Clear();
}
}
当我点击BUTTON3中日DataGridView1我选择的行中的信息被插入文本框,这样我就可以改变,以将Button4更新它们。我的问题是,当我尝试更新textBox1中的某些东西时,更新不适用于textBox1,也不适用于textBox2和3.但是,当我更新textBox 2或3中的信息时,它可以正常工作。
只是为了澄清..如果你只是试图改变'textbox2'和'textbox3'中的'Text'它可以正常工作,但是当你尝试'textbox1'以及'Text'没有更新?我会建议在'textBox1'行设置一个'breakpoint',看看发生了什么。 – KSdev
我认为错误在这一行,但我不知道如何修复它。 SqlCommand cmd = new SqlCommand(“Update SuperCars set Car = @ Car,mph = @ mph,price = @ price Where (Car = @ Car)“,con); – Cathy
在那里设置“断点”,看看它的值是多少。否则,您可以使用'Console.WriteLine'并查看其中的值。 – KSdev