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

时间:2022-04-22 15:37:27

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.

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

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?

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

2 个解决方案

#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)

不确定我是否完全理解你的问题。但你可以在表中查询0行(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.

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

Does that help?

这有帮助吗?

#2


1  

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

这是我根据shahkalpesh的答案提出的:

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"]);

#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)

不确定我是否完全理解你的问题。但你可以在表中查询0行(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.

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

Does that help?

这有帮助吗?

#2


1  

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

这是我根据shahkalpesh的答案提出的:

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"]);