我执行了一个存储过程

Dim conStr As String = "Dsn=dat;database=dat;option=0;port=0;server=localhost;uid=root"
Dim con As New OdbcConnection(conStr)
Dim cmd As New OdbcCommand("dat.selectRowCount", con)
con.Open()
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@startIndex", 5)
cmd.Parameters.AddWithValue("@endIndex", 15)
Dim reader As OdbcDataReader
reader = cmd.ExecuteReader
While reader.Read
'Some operations performed
End While


如果我需要将此reader添加到DataTable表示

Dim dt As DataTable = New DataTable("adm_ttemp")
dt.Load(reader)


但是我该如何将此阅读器分配给DataSet

最佳答案

为什么要寻找odbcReader to a dataSet作业?您可以直接将查询结果读取为上述答案中提到的dataset吗?

    Dim conStr As String = "Dsn=dat;database=dat;option=0;port=0;server=localhost;uid=root"
    Dim con As New OdbcConnection(conStr)
    Dim cmd As New OdbcCommand("dat.selectRowCount", con)
    con.Open()
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.AddWithValue("@startIndex", 5)
    cmd.Parameters.AddWithValue("@endIndex", 15)
    Dim DS As New DataSet
    '<---- lines to be noticed
    Using AD As New OdbcDataAdapter(cmd)
        AD.Fill(DS)
    End Using


您可以通过以下方式调用存储过程,只需尝试

    Dim conStr As String = "Dsn=dat;database=dat;option=0;port=0;server=localhost;uid=root"
    Dim con As New OdbcConnection(conStr)
    Dim cmd As New OdbcCommand("dat.selectRowCount", con)
    con.Open()
    '<----
    Dim callString As String = "CALL dat.selectRowCount(5,15)"
    cmd.CommandType = CommandType.StoredProcedure
    cmd.CommandText = callString
    '<-----
    Dim dlist As New DataList
    Dim DS As New DataSet
    Using AD As New OdbcDataAdapter(cmd)
        AD.Fill(DS)
    End Using

关于mysql - 将odbcReader分配给数据集,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26276750/

10-12 21:46