0

我解决了数据不显示的问题,并更正了下面的代码。

我需要使用 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")

感谢帮助。

谢谢

4

1 回答 1

0

您可以尝试使用 DB2Command 代替 IDbTransaction 吗?这就是我知道的方法,但您的要求可能与我的不同。

Dim conn As DB2Connection = New DB2Connection(cs)
Dim cmd As New DB2Command()
cmd.Connection = conn
cmd.CommandText = procName
cmd.CommandType = CommandType.StoredProcedure
Dim rdr AS DB2DataReader = Nothing

Try
     conn.Open()
     rdr = cmd.ExecuteReader()
     dgvData.DataSource = rdr
     dgvData.DataBind()
     rdr.Close()
Catch ex As DB2Exception
     ...
Finally
     conn.Close()
End Try
于 2014-01-10T20:59:05.850 回答