窗体gridview里数据怎么放dataset里 数据在窗体的gridview里手动修改后想放到dataset里,怎么放呢?高手指教一下,不胜感激! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DataTable dt = (DataTable)dataGridView1.DataSource; DataSet ds = new DataSet(); ds.Tables.Add(dt); 如果你是用DataSet.Tables[表名]绑定的,gridview界面所有的增删改都会反映到这个表里!无需另外的代码 是DataSet.Tables[表名]绑定,但我是想把在gridview里修改后的数据(增删改插都可能有)再更新到数据库,会自己反映到DataSet.Tables[表名]里吗?我用DataSet.Tables[表名]里的数据直接更新数据库里数据就可以? 请高手再指点一下,非常感谢,我几乎就是外行 :( //早说不就得了,非要转一个大弯? public void DGUpdate(String SQLString, DataGridView dataGridview,string connectionString) { dataGridview.EndEdit(); SQLDataAdapter Adapter = new SQLDataAdapter(); DataTable table = (DataTable)dataGridview.DataSource; using (SQLConnection connection = new SQLConnection(connectionString)) { Adapter.SelectCommand = new SQLCommand(SQLString, connection); SQLCommandBuilder builder = new SQLCommandBuilder(Adapter); Adapter.UpdateCommand = builder.GetUpdateCommand(); try { Adapter.Update(table); table.AcceptChanges(); } catch (Exception ex) { throw new Exception(ex.Message); } } } //调用 string sql="select * from 你之前select的表" DGUpdate(sql, DataGridView1,connectionString) 对,是这样的!这些知识,在MSDN上有详细说明,都是中文的,平时注意多用MSDN来辅助编程! 我写了一个方法,无论表中字段是增加还是减少都不影响方法的使用 WMI问题求助 一个表中有10条记录,在不使用id号的情况下,如何提取出第5到第8条的数据? c# winform 应用程序打包部署如何验证序列号 不能添加app.config,或者app.config可以添加在哪里(和webform不一样的?)?? C#的类 C#中怎么更新一个数据源 发布一个POP3组件,欢迎测试! 两个问题,望高手指教 mfc42ud.lib是什么库文件,起什么作用,为什么在我安装的vc中没有此文件 被包含的Form中的textBox控件,可以键盘操作,不能鼠标操作??? 会用Web Service的看过来
DataSet ds = new DataSet();
ds.Tables.Add(dt);
是DataSet.Tables[表名]绑定,但我是想把在gridview里修改后的数据(增删改插都可能有)再更新到数据库,会自己反映到DataSet.Tables[表名]里吗?我用DataSet.Tables[表名]里的数据直接更新数据库里数据就可以? 请高手再指点一下,非常感谢,我几乎就是外行 :(
public void DGUpdate(String SQLString, DataGridView dataGridview,string connectionString)
{
dataGridview.EndEdit();
SQLDataAdapter Adapter = new SQLDataAdapter();
DataTable table = (DataTable)dataGridview.DataSource;
using (SQLConnection connection = new SQLConnection(connectionString))
{
Adapter.SelectCommand = new SQLCommand(SQLString, connection);
SQLCommandBuilder builder = new SQLCommandBuilder(Adapter);
Adapter.UpdateCommand = builder.GetUpdateCommand();
try
{
Adapter.Update(table);
table.AcceptChanges(); } catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
//调用
string sql="select * from 你之前select的表"
DGUpdate(sql, DataGridView1,connectionString)
对,是这样的!这些知识,在MSDN上有详细说明,都是中文的,平时注意多用MSDN来辅助编程!