如何将数据从GridView保存到数据库? [英] How I can save the data from GridView to the database?
本文介绍了如何将数据从GridView保存到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
私有 void SelectFromDatabase()
{
字符串 OdbcConnectionString1 = getConnectionString();
OdbcConnection OdbcConnection1 = 新 OdbcConnection(OdbcConnectionString1);
字符串 OdbcSelectText1 = " ;
OdbcCommand OdbcSelectCommand1 = 新 OdbcCommand(OdbcSelectText1,OdbcConnection1);
OdbcDataAdapter OdbcDataAdapter1 = 新 OdbcDataAdapter();
尝试
{
OdbcConnection1.Open();
OdbcDataAdapter1.SelectCommand = OdbcSelectCommand1;
OdbcDataAdapter1.AcceptChangesDuringFill = true ;
int FillResult = OdbcDataAdapter1.Fill(myDataSet,TableName);
myDataSet.AcceptChanges();
fillGridViewbyDataset(myGridView,myDataSet,TableName);
Response.Write(" + FillResult);
}
捕获(Exception Exception1)
{
Response.Write(" + Exception1.Message) ;
}
最终
{
OdbcConnection1.Close();
}
}
私有 无效 fillGridViewbyDataset(GridView gv,DataSet ds,字符串 dt)
{
gv.DataSource = ds;
gv.DataMember = dt;
gv.DataBind();
}
我需要的是这样的:-
如何将Gridview保存到数据集,然后在我得到gridview更新时将数据集保存到数据库,但是数据库仍然没有任何更新!
看看这些文章S:
MSDN:ASP.NET 2.0的GridView示例:在GridView中编辑基础数据 [ ^ ]
使用GridView控件更新,删除记录 [选择,更新和删除ASP.NET GridView控件中的数据. [private void SelectFromDatabase() { string OdbcConnectionString1 = getConnectionString(); OdbcConnection OdbcConnection1 = new OdbcConnection(OdbcConnectionString1); string OdbcSelectText1 = "SELECT * FROM table"; OdbcCommand OdbcSelectCommand1 = new OdbcCommand(OdbcSelectText1, OdbcConnection1); OdbcDataAdapter OdbcDataAdapter1 = new OdbcDataAdapter(); try { OdbcConnection1.Open(); OdbcDataAdapter1.SelectCommand = OdbcSelectCommand1; OdbcDataAdapter1.AcceptChangesDuringFill = true; int FillResult = OdbcDataAdapter1.Fill(myDataSet, TableName); myDataSet.AcceptChanges(); fillGridViewbyDataset(myGridView, myDataSet, TableName); Response.Write("<br />SelectFromDatabase() Fill Result: " + FillResult); } catch (Exception Exception1) { Response.Write("<br /> SelectFromDatabase() Exception: " + Exception1.Message); } finally { OdbcConnection1.Close(); } } private void fillGridViewbyDataset(GridView gv, DataSet ds, string dt) { gv.DataSource = ds; gv.DataMember = dt; gv.DataBind(); }
what I need is something like:-
how to save Gridview to the DataSet then save the DataSet to the database as i got the gridview updates but the database still without any updates !!解决方案Have a look at these articleS:
MSDN: GridView Examples for ASP.NET 2.0: Editing the Underlying Data in a GridView[^]
Updating, Deleting records using GridView control[^]
Select, Update, and Delete Data in a ASP.NET GridView Control.[^]
to save the GridView to a dataset try :
DataSet ds = (DataSet) gridview.Datasource;
这篇关于如何将数据从GridView保存到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文