我解决了数据不显示的问题,并更正了下面的代码。
我需要使用 db2 中存储过程中返回的值填充数据集。我已经编写了一些连接到数据库的代码,并且似乎执行了 SP 并正在填充数据集,但我找不到能够弄清楚如何将数据从数据集显示到网格的方法。现在它是空白的,网格中没有数据。
Imports IBM.Data
Imports IBM.Data.DB2
Imports IBM.Data.DB2.DB2DataReader
'cs is the connection string you create in your application.
Dim conn As DB2Connection = New DB2Connection(cs)
conn.Open()
Dim trans As IDbTransaction = conn.BeginTransaction()
Dim cmd As IDbCommand = conn.CreateCommand()
Dim procName As String = "SP_Name"
cmd.Transaction = trans
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = procName
Dim db2da As New DB2DataAdapter
Dim db2ds As New DataSet
db2da.SelectCommand = cmd
cmd.ExecuteNonQuery()
db2da.Fill(db2ds, "Tab1")
Dim introwcount As Integer = db2ds.Tables("Tab1").Rows.Count
Dim intColumncount As Integer = db2ds.Tables("Tab1").Columns.Count
dgvData.DataSource = db2ds.Tables("Tab1")
感谢帮助。
谢谢