【问题标题】:MySQL Select Response Size .NETMySQL 选择响应大小 .NET
【发布时间】:2013-08-08 17:56:07
【问题描述】:

是否可以在读取 MySQL 响应之前接收它的大小?能够有一个进度条显示接收过程的状态。

Public Function QUERY(ByVal queryString As String, ByVal connection As MySqlConnection)
Try
    Dim newQuery As String() = Split(queryString, ":")
    For Each Query In newQuery
        Dim cmd As New MySqlCommand(Query, connection)
        Dim reader As MySqlDataReader
        reader = cmd.ExecuteReader()
        While reader.Read()
        End While
        reader.Close()
    Next
Catch ex As Exception
    console("Error: " & ex.Message)
    Return ex.Message
End Try
Return ""
End Function

【问题讨论】:

    标签: mysql .net database vb.net response


    【解决方案1】:

    不,使用 DataReader 在到达阅读器末尾之前,您无法知道查询返回的记录数。但是,您可以在查询中使用多个语句,其中第一个语句是您的数据计数。

    这是一个可能的例子:

    using con = new MySqlConnection("your_connection_string")
        con.Open()
        Dim cmd As MySqlCommand = new SqlCommand("SELECT COUNT(*) FROM MyTable;" & _
                                                 "SELECT * FROM MyTable", con)
        Dim dr as MySqlDataReader = cmd.ExecuteReader()
        if dr.HasRows Then        
            dr.Read()
            Dim count = Convert.ToInt32(dr(0))
            Console.WriteLine("Reading:" & count.ToString() & " records")
            dr.NextResult()
            while dr.Read()
                Console.WriteLine("Record:" + dr(dr.GetOrdinal("TableID")).ToString())
            End While
        End if
    End Using
    

    【讨论】:

      猜你喜欢
      • 2019-07-21
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-04
      相关资源
      最近更新 更多