private void button1_Click(object sender, EventAr
privatevoidbutton1_Click(objectsender,EventArgse){DataTabledt=(DataTable)this.dataGri...
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)this.dataGridView1.DataSource;
try
{
for (int i = 1; i < dataGridView1.Rows.Count; i++)
{
SqlConnection conn = new SqlConnection("server=boy;database=学生管理系统;uid=sa;pwd=608558558000");
conn.Open();
string str1 = "update Table_1 set 周一 =N'" + dt.Rows[i]["周一DataGridViewTextBoxColumn"] + "',周二=N'" + dt.Rows[i]["周二DataGridViewTextBoxColumn"];
string str2 = "',周三=N'" + dt.Rows[i]["周三DataGridViewTextBoxColumn"] + "',周四=N'" + dt.Rows[i]["周四DataGridViewTextBoxColumn"] + "',周五=N'" + dt.Rows[i]["周五DataGridViewTextBoxColumn"];
string str3 = "'where 输入="+i;
string str = str1 + str2 + str3;
SqlCommand cmd = new SqlCommand(str, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
MessageBox.Show("修改成功");
dataGridView1.ReadOnly = true;
}
catch
{
MessageBox.Show("修改失败,请检查是否违背了温馨提示里的规则。");
}
} 展开
{
DataTable dt = (DataTable)this.dataGridView1.DataSource;
try
{
for (int i = 1; i < dataGridView1.Rows.Count; i++)
{
SqlConnection conn = new SqlConnection("server=boy;database=学生管理系统;uid=sa;pwd=608558558000");
conn.Open();
string str1 = "update Table_1 set 周一 =N'" + dt.Rows[i]["周一DataGridViewTextBoxColumn"] + "',周二=N'" + dt.Rows[i]["周二DataGridViewTextBoxColumn"];
string str2 = "',周三=N'" + dt.Rows[i]["周三DataGridViewTextBoxColumn"] + "',周四=N'" + dt.Rows[i]["周四DataGridViewTextBoxColumn"] + "',周五=N'" + dt.Rows[i]["周五DataGridViewTextBoxColumn"];
string str3 = "'where 输入="+i;
string str = str1 + str2 + str3;
SqlCommand cmd = new SqlCommand(str, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
MessageBox.Show("修改成功");
dataGridView1.ReadOnly = true;
}
catch
{
MessageBox.Show("修改失败,请检查是否违背了温馨提示里的规则。");
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询