gpt4 book ai didi

vb.net - 数据表不知道其主键

转载 作者:行者123 更新时间:2023-12-01 22:03:48 25 4
gpt4 key购买 nike

我正在尝试通过查询每个列的自动增量属性来查询数据表以建立主键[标识列]。但是它始终为 false(对于 Idenity/PK 列)。

查询表主键集合显示数据表不认为它具有 PK。;

  Dim dc As DataColumn() = dt.PrimaryKey
Debug.WriteLine(dc.Count) 'Result is 0

正在填充数据表......

Using cn As SqlConnection = MyApp.GetConnection
Using cmd As New SqlCommand(strSQL, cn)
Using da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
Try
da.Fill(ds)

Return ds

Catch ex As Exception
MyAppClass.LogWarning(ex, EventLogEntryType.Error)
Throw
End Try
End Using
End Using
End Using

相关表的主键是:([myTableId] [int] IDENTITY(1,1) NOT NULL)。及其 pk :约束 [PK_myTablesPK] 主键聚集 ( [myTableId] ASC )

这里有人遇到了同样的问题(也许比我写的更清楚):http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/c6abdeef-0cb0-42f5-a5f1-10dc4d81df4a/

我假设我缺少一些简单的东西,有人愿意启发我吗?

最佳答案

使用 fillschema 解决了我的问题;

da.FillSchema(ds, SchemaType.Mapped, table.tableName)
da.Fill(ds, table.tableName)

The DataAdapter object is optimized for read-only scenarios by default. The Fill method only retrieves the amount of schema that is necessary to populate a DataSet object. To obtain the additional schema that are necessary to update or validate DataSet objects, use one of the following methods for DataSet objects that are populated by the DataAdapater:

  • Use the FillSchema method of the DataAdapter.
  • Use the AddWithKey enumeration for the MissingSchemaAction property of the DataAdapter.

This article describes how to choose between these two methods when you want to populate updateable DataSet objects with the DataAdapter.

REF : http://support.microsoft.com/kb/310128

关于vb.net - 数据表不知道其主键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/662394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com