ASP.NET 中的 GridView
我正在使用 DataGrid 控件。我将它与ADO.NET绑定。
我希望如果有任何新数据出现,它应该在网格视图中将其与旧数据列一起附加。如何做到这一点?
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection();
con.ConnectionString = "server = (local); initial Catalog = SQLTraining; Integrated Security = SSPI";
con.Open();
string Selectstring = "select "+attribute_name+" from "+tablename+"";
SqlCommand cmd = new SqlCommand(Selectstring, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
gd.DataSource = dt;
gd.DataBind();
i am using DataGrid control. i bind it with the ADO.NET.
i want if any new data comes it should append it with the old data column wise in grid view. how this can be done?
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection();
con.ConnectionString = "server = (local); initial Catalog = SQLTraining; Integrated Security = SSPI";
con.Open();
string Selectstring = "select "+attribute_name+" from "+tablename+"";
SqlCommand cmd = new SqlCommand(Selectstring, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
gd.DataSource = dt;
gd.DataBind();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用
DataTable.Merge()
:
无论如何,考虑使用
using(){}
块:Try to use
DataTable.Merge()
:Anyway, consider to use
using(){}
block:您可以使用 DataTable.Merge 方法。请查看 MSDN。
You could use
DataTable.Merge
method. Have a look at MSDN.使用此代码合并数据集
use this code for merge the dataset