将记录绑定到网格而不存储在数据库中 [英] bind record to grid without storing in databse

查看:81
本文介绍了将记录绑定到网格而不存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将记录插入数据集而不将其存储在数据库中并显示在网格中...现在点击保存按钮时如何将其存储在数据库中

解决方案
1。在Datatable中添加代码的示例



DataTable dt = new DataTable();



//添加数据列

DataColumn workCol = dt.Columns.Add(FirstName,typeof(String));



dt.Columns.Add( LastName,typeof(String));

dt.Columns.Add(Blog,typeof(String));

dt.Columns.Add(City ,typeof(String));

dt.Columns.Add(Country,typeof(String));



//添加在数据行中

DataRow newRow = dt.NewRow();



newRow [firstname] =Arun;

newRow [lastname] =Prakash;

newRow [Blog] =http://royalarun.blogspot.com/;

newRow [city] =Coimbatore;

newRow [country] =India;



dt。 Rows.Add(newRow);





2.您可以将数据表存储在Viewstate中,然后将该记录绑定到网格中。如果添加任何新内容,请在数据表中添加新行并更新视图状态数据表然后在网格中绑定,



3.最后使用C#中的SqlBulkCopy使用批量插入数据表将所有记录插入SQL Server,检查以下链接



http:// www。 morgantechspace.com/2013/08/bulk-insert-records-into-sql-server.html [ ^ ]


hi how to insert a record in to dataset without storing it in database and show in grid...now when click on the save button how to store it in database finally

解决方案

1. Example for adding code in Datatable

DataTable dt = new DataTable();

//Add Datacolumn
DataColumn workCol = dt.Columns.Add("FirstName", typeof(String));

dt.Columns.Add("LastName", typeof(String));
dt.Columns.Add("Blog", typeof(String));
dt.Columns.Add("City", typeof(String));
dt.Columns.Add("Country", typeof(String));

//Add in the datarow
DataRow newRow = dt.NewRow();

newRow["firstname"] = "Arun";
newRow["lastname"] = "Prakash";
newRow["Blog"] = "http://royalarun.blogspot.com/";
newRow["city"] = "Coimbatore";
newRow["country"] = "India";

dt.Rows.Add(newRow);


2. You can store the datatable in Viewstate, and then bind the record in grid, Like wise if any new thing is added add new row in the datatable and update the view state datatable.Then bind in grid,

3. Finally insert all the records using Bulk Insert Datatable into SQL Server using SqlBulkCopy in C#, check below link

http://www.morgantechspace.com/2013/08/bulk-insert-records-into-sql-server.html[^]


这篇关于将记录绑定到网格而不存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆