如何通过 OleDb 确定 MS Access 字段大小

发布于 2024-07-06 08:57:08 字数 222 浏览 8 评论 0原文

现有应用程序是用 C# 编写的。 在启动期间,应用程序调用虚拟方法来对数据库进行更改(例如,新版本可能需要计算新字段或其他内容)。 将打开的 OleDb 连接传递到该方法中。

我需要更改字段宽度。 ALTER TABLE 语句工作正常。 但如果字段已经是适当的大小,我想避免执行 ALTER TABLE 语句。 有没有办法使用相同的 OleDb 连接来确定 MS Access 字段的大小?

The existing application is in C#. During startup the application calls a virtual method to make changes to the database (for example a new revision may need to calculate a new field or something). An open OleDb connection is passed into the method.

I need to change a field width. The ALTER TABLE statement is working fine. But I would like to avoid executing the ALTER TABLE statement if the field is already the appropriate size. Is there a way to determine the size of an MS Access field using the same OleDb connection?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅暮の光 2024-07-13 08:57:08

这是我根据 shhkalpesh 的回答得出的结论:

var command = new OleDbCommand("SELECT FIELD FROM TABLE", connection); 
var reader = command.ExecuteReader(CommandBehavior.SchemaOnly); 
var schema = reader.GetSchemaTable(); 
var size = Convert.ToInt32(table.Rows[0]["ColumnSize"]);

Here's what I came up with based on shahkalpesh's answer:

var command = new OleDbCommand("SELECT FIELD FROM TABLE", connection); 
var reader = command.ExecuteReader(CommandBehavior.SchemaOnly); 
var schema = reader.GetSchemaTable(); 
var size = Convert.ToInt32(table.Rows[0]["ColumnSize"]);
野稚 2024-07-13 08:57:08

不确定我是否完全理解你的问题。
但是您可以查询表中的 0 行 (SELECT 1 FROM myTable WHERE 1= 0)

并且您可以使用记录的字段集合,通过名称或索引引用该字段
并使用字段的属性,如大小、类型等。

这有帮助吗?

Not sure if I understand your question completely.
But you could query the table for 0 rows (SELECT 1 FROM myTable WHERE 1= 0)

And you could use recordet's field collection, refer to that field by name or index
and use field's property like size, type etc.

Does that help?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文