当executereader从表中读取行时,如何将行添加到数据表中?
我想使用 C# 编码将executereader 读取的行添加到新数据表中
I want to add the rows that are read by executereader to the new datatable with C# coding
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的问题中有太多未知数。例如,数据表是类型化的还是非类型化的?列类型有哪些?等等。
但无论如何,这是一个一般的例子。我根据此处给出的原始示例改编了代码。
private static void ReadOrderData(string connectionString)
{
字符串查询字符串 =
“从 dbo.Orders 中选择订单 ID、客户 ID;”;
}
There are too many unknowns in your question. Foreg, is the data table typed or untyped? What are the column types? And so forth.
But anyway, here's a general example. I adapted the code from the original sample given here.
private static void ReadOrderData(string connectionString)
{
string queryString =
"SELECT OrderID, CustomerID FROM dbo.Orders;";
}
创建一个 dataTable 对象,其列与 datareader 的列相同。请看下面的代码。
例如:
所以在你的数据表中你有两列[ID和标记]。
检索数据
编写一个函数来添加新行
这样您就可以向数据表添加值。
Make a dataTable oject with the columns same as that of the datareader. Pls have a look at the code below.
Eg:
So in your datatable u have two columns[ID and mark].
retriving data
Write a function to add New Row
This way u can able to add values to dataTable.