获取DataColumn的原始数据格式
如何获取 DataColumn 对象的原始数据格式(在数据库中)?
我有来自 DataTable 的 DataColumn 对象,它是打开 DBCommand SQL“选择”查询的结果的一部分。
如何获取有关查询返回的原始数据格式的信息(即“varchar[50]”等)。
我知道 DataColumn.DataType 但这里的信息不够具体,例如无法区分 varchar 和 char 或区分日期和时间戳或获取 varchar 字段的最大长度等等。
直接从服务器数据库方案获取信息不是我正在寻找的解决方案,因为查询文本是由用户输入的,我不想自己解析文本以找出正在使用哪个表的哪一列,因为可能有些列在数据库中没有相应的条目(例如 select ColumnA || Column B, 'SomeLiteral', 12 * ColumnC, null from MyTable)
How can I get the original data format (in the database) of a DataColumn object?
I have DataColumn objects from a DataTable that is part of the result of opening a DBCommand SQL "select" query.
How do I get information on the original data formats returned by the query (i.e. "varchar[50]" and so forth).
I know DataColumn.DataType but the information here is not specific enough, for example it is not possible to distinguish varchar and char or to distinguish date and timestamp or to get the maximum length of a varchar field and so on.
Getting information from the server database scheme directly is not the solution I am looking for, because the query text is entered by the user and I don't want to parse the text myself to find out what column of what table is being used and because there can be columns that don't have a corresponding entry in the database (e.g. select ColumnA || Column B, 'SomeLiteral', 12 * ColumnC, null from MyTable)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试类似的操作,并检查结果(在 schemaTable 表中)。
You could try something like this, and examine the results (in the schemaTable table).
听起来您正在获取一个临时字符串,获取一个数据表,并尝试确定其数据类型和长度。
尝试另一种方法,直接查询 SQL Server。正如您所发现的,DataColumn 没有您需要的所有信息。
Sounds like you're taking an ad-hoc string, getting a DataTable, and trying to determine its datatype and length.
Try another approach by querying SQL Server directly. As you've discovered, DataColumn doesn't have all the info you need.