datagridview数据更新事件的编写 datagridview数据更新 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DataGridView我也研究了一段时间, 我觉得你的问题就是那个地方把数据给改了。如果方便的话, 可以把你的代码贴出来。 你可以在DataGridView的触发事件中看看这两个函数。cellvalidating and cellvalidated DataGridView数据更新事件的编写示例//更新数据事件 public void Update(Instance it) { SqlConnection sc = GetConnection();//调用GetConnections()方法,得到连接对象 try { sc.Open();//打开到数据库的连接 SqlCommand cmd = new SqlCommand(//创建SqlCommand对象 "update tb_friend set phone=@phone where names=@names", sc); cmd.Parameters.Add("@names", SqlDbType.VarChar).Value = it.Name;//向SqlCommand对象添加参数 cmd.Parameters.Add("phone", SqlDbType.VarChar).Value = it.phone;//向SqlCommand对象添加参数 cmd.ExecuteNonQuery();//执行SqlCommand对象中的SQL命令 } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (sc.State == ConnectionState.Open)//判断是否连接数据库 { sc.Close();//如果已经连接则关闭连接 } } }//codego.net/tags/1/1///绑定dataGridView控件实现更新事件按钮private void btn_update_Click(object sender, EventArgs e) { //调用datatier对象的Update()方法,更改数据库中的信息 dt.Update(new Instance() { Name = txt_name_update.Text, phone = txt_phone_update.Text }); dataGridView1.DataSource = dt.Select();//更新dataGridView1控件中的信息 Clear();//清空TextBox控件中的文本 } 大侠,我的代码如下: private void dataGridView_CurveDivide_CellEndEdit(object sender, DataGridViewCellEventArgs e) { int rowIndex = dataGridView_CurveDivide.CurrentCell.RowIndex; int columnIndex = dataGridView_CurveDivide.CurrentCell.ColumnIndex; change = Convert.ToDouble(dataGridView_CurveDivide.CurrentCell.Value); CalculateNewValue(change,rowindex,columnindex);//根据新输入的值重新计算数组中的值 ImportDataToDatagridview();//把数组中的数据导入到datagridview中 }我把 ImportDataToDatagridview()写入到两个验证函数里没有用哎??? 不用微软自己的SQLCE的库怎么从C#访问SQLCE数据库 怎么传this C++中的指针类型,在C#中要用什么类型替换啊? 无法建立sql的安全连接 SQLSERVER大量记录下发有何办法? C++调用C#的回调函数问题 C# 把当前页面生成WORD文档 c#中iframe网页框架问题,求解,急! 没分了,请帮忙解决关于SocketAsyncEventArgs接收的数据不正确的问题,请高手解答 在屏幕指定位置如何打开其他EXE sendMessage 缺少程序集引用
如果方便的话, 可以把你的代码贴出来。
//更新数据事件
public void Update(Instance it)
{
SqlConnection sc = GetConnection();//调用GetConnections()方法,得到连接对象
try
{
sc.Open();//打开到数据库的连接
SqlCommand cmd = new SqlCommand(//创建SqlCommand对象
"update tb_friend set phone=@phone where names=@names", sc);
cmd.Parameters.Add("@names", SqlDbType.VarChar).Value = it.Name;//向SqlCommand对象添加参数
cmd.Parameters.Add("phone", SqlDbType.VarChar).Value = it.phone;//向SqlCommand对象添加参数
cmd.ExecuteNonQuery();//执行SqlCommand对象中的SQL命令
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
if (sc.State == ConnectionState.Open)//判断是否连接数据库
{
sc.Close();//如果已经连接则关闭连接
}
}
}//codego.net/tags/1/1/
//绑定dataGridView控件实现更新事件按钮
private void btn_update_Click(object sender, EventArgs e)
{
//调用datatier对象的Update()方法,更改数据库中的信息
dt.Update(new Instance() { Name = txt_name_update.Text, phone = txt_phone_update.Text });
dataGridView1.DataSource = dt.Select();//更新dataGridView1控件中的信息
Clear();//清空TextBox控件中的文本
}
private void dataGridView_CurveDivide_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
int rowIndex = dataGridView_CurveDivide.CurrentCell.RowIndex;
int columnIndex = dataGridView_CurveDivide.CurrentCell.ColumnIndex;
change = Convert.ToDouble(dataGridView_CurveDivide.CurrentCell.Value);
CalculateNewValue(change,rowindex,columnindex);//根据新输入的值重新计算数组中的值
ImportDataToDatagridview();//把数组中的数据导入到datagridview中
}
我把 ImportDataToDatagridview()写入到两个验证函数里没有用哎???