0

我在这里有堆栈但没有去我有一个连接到数据库的循环,但最近 2 天在计算行号时遇到问题。并且找不到解决方案

    Dim row as Integer
    For i = 100 To 120
        Dim DBconn As MySql.Data.MySqlClient.MySqlConnection = New MySql.Data.MySqlClient.MySqlConnection(My.Settings.DBConnStr)
        Dim da As MySql.Data.MySqlClient.MySqlDataAdapter
        Dim dt As New DataTable
        Dim sqlcmd As New MySql.Data.MySqlClient.MySqlCommand
        sql = "SELECT Sum(D), Sum(P) FROM fin  WHERE K like '" & i.ToString & "%' "
        DBconn.Open()
        da = New MySql.Data.MySqlClient.MySqlDataAdapter(sql, DBconn)
        da.Fill(dt)
        DBconn.Close()
        row = dt.Rows.Count
        MsgBox("i=" & i & "    rows=" & row)
        dt.Clear()
    Next

MSG Box 总是告诉我 RowCount 是 1,当我手动查询 MYSQL Diferent i Gives me Diferent Rows 时。

4

1 回答 1

0

我确定您是如何让数据适配器填充数据表的。它应该填充数据集。它应该是

   DIM ds as New Dataset()
   da = New MySql.Data.MySqlClient.MySqlDataAdapter(sql, DBconn) 
   da.Fill(ds)
   DIM rowCount = ds.Table(0).Rows.Count

试试这个

   DIM rowCount = ds.Tables(0).Select().Count
于 2013-10-19T23:31:21.533 回答