本文介绍了DataColumn的AutoIncrement始终返回False的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣检查列是否具有autoincrement/allowdbnull属性.

I am interested to check out whether column has an autoincrement/allowdbnull property .

下面有这段代码,尽管我已经有一个具有autoincrement/allowdbnull属性的列,但它总是给我错误.

Having this code below , gives me always false although I already have one column that has autoincrement/allowdbnull property.

Dim dt As New DataTable()
Dim con As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" &             Application.StartupPath & "\test.mdb"
Dim sql As String = "SELECT * from teachers"
Dim i As Integer



Dim dataAdapter As New OleDb.OleDbDataAdapter(sql, con)
dataAdapter.Fill(dt)
dataAdapter.Dispose()



For Each column As DataColumn In dt.Columns

TextBox1.Text = TextBox1.Text & column.ColumnName & "      " & column.AutoIncrement & "        " & column.AllowDBNull & vbCrLf

Next

谢谢.

推荐答案

要使代码正常工作,您只需添加(在调用Fill方法之前)

To make your code work you need to add (before the call to Fill method) just

  dataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey

这将强制适配器检索有关主键和自动编号字段的信息

This will force the adapter to retrieve the information about primary keys and autonumber fields

MSDN MissingSchemaAction枚举

这篇关于DataColumn的AutoIncrement始终返回False的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 19:57