gpt4 book ai didi

database - 将数据库表中的列名放入列表中

转载 作者:搜寻专家 更新时间:2023-10-30 20:01:16 24 4
gpt4 key购买 nike

我正在尝试将 Microsoft Access 数据库中的表中的列名称放入列表变量中。到目前为止我已经这样做了但是我试图将它添加到主题变量的行不起作用并且出现了错误

predefined type ‘valuetuple(of,,,)’ is not defined or imported.

代码是:

Dim topic = topic()
Dim filtervalues = {Nothing, Nothing, "Results", Nothing}
Dim counter As Integer = 0
Using con = _
New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database.mdb")
Dim columns = con.GetSchema("columns", filtervalues)

For Each row As DataRow In columns.Rows
topic(counter) = ("{0,-20}{1}", row("column_name"), row("data_type"))
counter = +1
Next
End Using

最佳答案

根据 Value Tupels 上的文档如果您使用的是 4.7 之前的框架版本,则必须获取 NuGet 包 System.ValueTuple:

Important

Tuple support requires the ValueTuple type. If the .NET Framework 4.7 is not installed, you must add the NuGet package System.ValueTuple, which is available on the NuGet Gallery. Without this package, you may get a compilation error similar to, "Predefined type 'ValueTuple(Of,,,)' is not defined or imported."

在 Visual Studio 2017 中,右键单击您的解决方案并选择“管理解决方案的 NuGet 包...”。在搜索框中输入“valuetuple”。选择“System.ValueTuple”并在右侧单击要安装包的项目的复选框,然后单击“安装”。

参见:NuGet Package Manager UI

此外,您必须将列表变量声明为

Dim topic = New List(Of (String, String, String))

并添加新元素

topic.Add(("{0,-20}{1}", row("column_name"), row("data_type")))

不再需要计数器了。


或者,您可以使用字符串列表并使用字符串插值格式化字符串

Dim topic = New List(Of String)
Dim filtervalues = {Nothing, Nothing, "Results", Nothing}
Using con =
New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database.mdb")
Dim columns = con.GetSchema("columns", filtervalues)

For Each row As DataRow In columns.Rows
topic.Add($"{row("column_name"),-20}{row("data_type")}")
Next
End Using

关于database - 将数据库表中的列名放入列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48061513/

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