日期:2014-05-20  浏览次数:20948 次

dateGridView如何回写到数据库
dateGridView将数据从数据库中掉入内存,比如
OracleConnection   conn   =   new   OracleConnection(Properties.Settings.Default.ConnectionString);
OracleDataAdapter   adapter   =   new   OracleDataAdapter( "select   *   from   test ",   conn);
DataTable   dt   =   new   DataTable();
this.bindingSource1.DataSource   =   dt;
adapter.Fill(dt);请问此时如何对表进行update操作(update完后页面要刷新),然后再将update的数据回写到数据库怎么做

------解决方案--------------------
通过适配器把修改推回数据库就可以了啊。
------解决方案--------------------
我就不写例子了,MSDN上有相关例子,你先看下吧,搞不定再说..

public DataSet CreateCmdsAndUpdate(DataSet dataSet, string connectionString,
string queryString, string tableName)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = new OleDbCommand(queryString, connection);
OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);

connection.Open();

DataSet customers = new DataSet();
adapter.Fill(customers);

//code to modify data in dataset here
//注意这里你对DataTable中的值进行update,insert,delete ..

adapter.Update(customers, tableName);

return customers;
}
}

以上是OleDb的,你换成相应SqlDataAdapter,SqlCommandBuilder等一样用...
------解决方案--------------------
mark