问题标签 [datarow]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
31194 浏览

.net - 如何将 DataTable.Select() 的结果绑定到 ListBox 控件?

我有以下代码:

DataTable.Select()方法返回一个对象数组System.Data.DataRow

无论我在ListBox.DisplayMember属性中指定什么,我所看到的只是列表框,其中项目的正确数量全部显示为,System.Data.DataRow而不是"name"列中我想要的值!

是否可以从 绑定到结果数组DataTable.Select(),而不是循环遍历它并将每个数组添加到ListBox

(我对循环没有问题,但似乎不是一个优雅的结局!)

0 投票
4 回答
109158 浏览

.net - How do I find out if a column exists in a VB.Net DataRow

I am reading an XML file into a DataSet and need to get the data out of the DataSet. Since it is a user-editable config file the fields may or may not be there. To handle missing fields well I'd like to make sure each column in the DataRow exists and is not DBNull.

I already check for DBNull but I don't know how to make sure the column exists without having it throw an exception or using a function that loops over all the column names. What is the best method to do this?

0 投票
3 回答
19051 浏览

c# - 在 DataRow 中设置项目的值不起作用

我正在尝试将 DataTable 中的所有 DateTime 值转换为字符串。这是我使用的方法:

在这条线工作之后:

我检查了 dataTable.Rows[rowIndex][i] 的值,发现它仍然是 DateTime,而不是字符串。为什么会发生这种情况,我该如何解决?

编辑:我正在尝试这样做,因为我正在与 api 作斗争,不幸的是我无法选择使用哪个组件。

0 投票
4 回答
47632 浏览

c# - 将 DataRowCollection 转换为 DataRow[]

将 DataRowCollection 实例转换为 DataRow[] 的最佳执行方式是什么?

0 投票
1 回答
25714 浏览

c# - 如何从 C# 中的 DataRow 读取字节数组?

我有一个DataSet通过 aDataTable正确填充单个DataRow的 a TableAdapter

我可以使用如下代码从 DataRow 中提取数据:

我有另一列名为 DataFile 类型的列varbinary(max)

当我尝试从与上面相同的列中提取该列的数据时DataRow,我什么也得不到。

如果我在这个位置放置一个断点,我可以查看 dataFileDataRow,查看 ItemArray 属性并看到二进制数据位于 ItemArray 中的位置 5。

我尝试使用它的索引直接访问 ItemArray,但字节数组没有被复制到 fileFromDatabase 变量。

我还注意到将 fileFromDatabase 添加到我的手表会产生此错误:

“当前上下文中不存在名称‘fileFromDatabase’”

执行仍然与 fileFromDatabase 的定义在同一个块中,所以我不明白它是如何脱离上下文的。

我将 Visual Studio 的配置设置为 Release 而不是 Debug。这导致我在尝试检查 fileFromDatabase 时看不到我正在寻找的实时调试信息。从 Release 切换到 Debug 后,我现在可以在手表中看到变量,并且可以验证上面的代码是否正常工作。

0 投票
3 回答
71741 浏览

asp.net - 将新行添加到数据表的顶部

当我们使用 datatable.newrow 命令时,会在行的底部添加一个新的空行。但是我希望将 newrow 添加到数据表的顶部。我怎样才能做到?

0 投票
1 回答
12192 浏览

c# - C# 反射:从 Typed DataSet 中获取 DataRow 的字段

我目前正在构建一个方法,该方法DataRow从类型化的 DataSet 中获取一个类型的对象,然后返回DataRow 中字段的JSON格式的字符串(用于 Web 服务)。

通过使用System.Reflection,我正在做这样的事情:

然后在foreach语句中,我将迭代每个字段并获取字段名称和值,并将其格式化为 JSON。


问题是,当迭代props(类型PropertyInfo[])时,我得到了我不想被迭代的属性:

替代文字 http://img88.imageshack.us/img88/2001/datarowreflectionht0.gif

从上图中可以看出,我只需要数组0 - 11中的字段props,因为这些字段是这个特定类型行的“真实字段”。

所以我的问题是,我怎样才能只获取 Typed DataRow 的字段,而不是其他“元数据”?


[更新解决方案]

正如Mehrdad Afshari建议的那样Reflection,我使用的是Table.Columns数组而不是 using 。

这是完成的功能:

0 投票
11 回答
8960 浏览

.net - 在 .Net DataSets 上使用列名或列索引会更好吗?

从 DataRow 检索值时,使用列名还是列索引更好?

列名更具可读性和更易于维护:

虽然列索引更快(我认为):

如果您决定混淆数据库,使用列名会中断吗?

0 投票
2 回答
269 浏览

.net - 选择主键

[更新:MS SQL Server 2005]

嗨,是否可以选择一堆值,然后在 select 语句中指定一列作为主键?

我问这个是因为我想利用 .net 中的 DataRow 查找方法,谢谢。

0 投票
1 回答
188 浏览

linq - LINQ(或任何东西)将对象列表中的项目添加到数据网格中的对象行?

说对象如下:

其中标签是动态的,但有一个标签列表存储在核心数据对象的 Collection 中。

我希望能够像这样在数据网格中显示它:

我遗漏了错误,但如果需要,它可能在那里。

干杯