如下代码,为什么修改时不能更新呢?dataGridView.AllowUserToAddRows=false;
dataGridView.ReadOnly=true;
SqlDataAdapter da=null ;
SqlCommandBuilder cb=null ;
SqlCommand sqlcom=null ;
SqlConnection sqlcon = null;
DataTable dt = null;
private void showtm() {
if (sqlcon.State == ConnectionState.Open)
{
string comstr = string.Empty;
switch (tabControl_tmlist.SelectedIndex)
{
case 0:
comstr = "SELECT * FROM TIANKONGTI";
break;
case 1:
comstr = "SELECT * FROM PANDUANTI";
break;
case 2:
comstr = "SELECT * FROM XUANZETI";
break;
case 3:
comstr = "SELECT * FROM WENDATI";
break;
}
da = new SqlDataAdapter(comstr,sqlcon);
cb = new SqlCommandBuilder(da);
dt = new DataTable();
da.Fill(dt);
dataGridView_tmlist.DataSource = dt;
else { //未连接
}
}
//删除,可更新
private void StripMenuItem_tkgl_del_Click(object sender, EventArgs e)
{
dataGridView_tmlist.Rows.Remove(dataGridView_tmlist.SelectedRows[0]);
da.Update(dt);
}
//修改为什么不能更新?
private void StripMenuItem_tkgl_modfy_Click(object sender, EventArgs e)
{
Form_Modfy modfy = new Form_Modfy();
modfy.index = tabControl_tmlist.SelectedIndex;
modfy.selectrow = dataGridView_tmlist.SelectedRows[0];
if (modfy.ShowDialog() == DialogResult.OK) {
for (int i = 1; i < dataGridView_tmlist.SelectedRows[0].Cells.Count; i++)
{
dataGridView_tmlist.SelectedRows[0].Cells[i].Value = modfy.selectrow.Cells[i].Value;
}
da.Update(dt);
}
}
DataGridView
dataGridView.ReadOnly=true;
SqlDataAdapter da=null ;
SqlCommandBuilder cb=null ;
SqlCommand sqlcom=null ;
SqlConnection sqlcon = null;
DataTable dt = null;
private void showtm() {
if (sqlcon.State == ConnectionState.Open)
{
string comstr = string.Empty;
switch (tabControl_tmlist.SelectedIndex)
{
case 0:
comstr = "SELECT * FROM TIANKONGTI";
break;
case 1:
comstr = "SELECT * FROM PANDUANTI";
break;
case 2:
comstr = "SELECT * FROM XUANZETI";
break;
case 3:
comstr = "SELECT * FROM WENDATI";
break;
}
da = new SqlDataAdapter(comstr,sqlcon);
cb = new SqlCommandBuilder(da);
dt = new DataTable();
da.Fill(dt);
dataGridView_tmlist.DataSource = dt;
else { //未连接
}
}
//删除,可更新
private void StripMenuItem_tkgl_del_Click(object sender, EventArgs e)
{
dataGridView_tmlist.Rows.Remove(dataGridView_tmlist.SelectedRows[0]);
da.Update(dt);
}
//修改为什么不能更新?
private void StripMenuItem_tkgl_modfy_Click(object sender, EventArgs e)
{
Form_Modfy modfy = new Form_Modfy();
modfy.index = tabControl_tmlist.SelectedIndex;
modfy.selectrow = dataGridView_tmlist.SelectedRows[0];
if (modfy.ShowDialog() == DialogResult.OK) {
for (int i = 1; i < dataGridView_tmlist.SelectedRows[0].Cells.Count; i++)
{
dataGridView_tmlist.SelectedRows[0].Cells[i].Value = modfy.selectrow.Cells[i].Value;
}
da.Update(dt);
}
}
DataGridView
解决方案 »
- c# 用webqq发送消息
- 关于编写的 windows 服务
- C#无法更新数据库的问题
- 怎么将一个C#程序生成一个.EXE文件
- 用C# 下载的 swf文件不完整,大家帮一下忙啊,查不出什么原因。
- UploadFileDescription=HttpContext.Current.Request.PhysicalApplicationPath;UploadFileDestination += CurrentImagesFolder.Value;Upl
- 大侠教我:为什么不能显示列表中的数据?
- 水晶报表拉模式的问题,先送上100分!
- 怎样设置光标位置﹖
- 请教,怎样弹出一个对话框让用户选择一个目录
- 求助:未处理——ArgumentException
- 课程继承要怎么讲
dataGridView.ReadOnly=false;
da.Update(dt);
dataGridView.ReadOnly=true;
???????????
http://bbs.csdn.net/topics/390510770