问题描述
大家好,您堆放过鲜花.我在这里有些两难.我需要获取您可以在字段中输入的最大字符数,但是我没有成功,并且Google并没有产生与我所需类似的内容
Hi all you Stack Overflowers. I am having bit of a dilemma here. I need to obtain the Maximum of characters you may enter into a field but I have had no success and Google did not produce anyhing similar to what I need
这是我的代码
lvwDestination.Columns.Add("Fields in Database", 150, HorizontalAlignment.Left);
lvwDestination.Columns.Add("DataType", 100, HorizontalAlignment.Left);
lvwDestination.Columns.Add("Max", 100, HorizontalAlignment.Left);
for (int i = 0; i < DataTable.Columns.Count; i++)
{
_lvwItem = new ListViewItem(DataTable.Columns[i].ColumnName, 0);
_lvwItem.Name = DataTable.Columns[i].ColumnName;
_lvwItem.SubItems.Add(DataTable.Columns[i].DataType.Name.ToString());
_lvwItem.SubItems.Add(DataTable.Columns[i].MaxLength.ToString());
lvwDestination.Items.AddRange(new ListViewItem[] { _lvwItem });
}
现在您可以看到我已经尝试过
Now as you can see I have tried
_lvwItem.SubItems.Add(DataTable.Columns[i].MaxLength.ToString());
,但是唯一要考虑的是每列-1.我还确保我的列确实具有属性字段大小属性. .ColumnName和.DataType可以完美地工作,但是.MaxLength总是产生-1.预先感谢任何可能提出解决方案的人.
but the only thing that this came up with is -1 for every column. I have also made sure that my columns do in fact have the property field size attribute on. The .ColumnName and .DataType works perfectly but .MaxLength produces -1 always.Thanks in advance for anyone that might be able to come up with a solution.
推荐答案
在调用Fill
方法之前尝试设置以下属性:DataAdapter
的OledbDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
...
try setting following property: OledbDataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
of your DataAdapter
before calling the Fill
method...
这篇关于获取访问列的最大字段大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!