1

我正在开发一个应用程序,我写了下面的代码,

Public Function CreateDatatable(ByVal SqlQuery As String, ByVal strTable As String, Optional ByVal OrderbyField As String = "") As DataTable

        If InitDB() Then
            Try
                Dim sqlAdapter As New MySqlDataAdapter()
                Dim dt As New DataTable()
                If SqlQuery = "" Then SqlQuery = "Select * from " & strTable & IIf(OrderbyField <> "", " order by " & OrderbyField, "")
                Dim cmd As New MySqlCommand(SqlQuery, MySQLCon)
                cmd.CommandTimeout = 18000
                sqlAdapter.SelectCommand = cmd
                dt.TableName = strTable
                sqlAdapter.Fill(dt)
                CreateDatatable = dt
            Catch ex As Exception
                ServiceLog.WriteEntry("CreateDatatable Exception:" & ex.Message)
            End Try
        Else
            CreateDatatable = Nothing
        End If

    End Function

运行代码后出现此错误。

MySql.Data.MySqlClient.MySqlException={"在命令执行期间遇到致命错误。"} 在 MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior 行为) 在 MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior 行为) 在 System. Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior 行为)在 System.Data.Common.DbDataAdapter.FillInternal(DataSet 数据集,DataTable[] 数据表,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand 命令,CommandBehavior 行为) 在 System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) 在 AgilityNewsService.clsDataware_MySQL 的 System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand 命令, CommandBehavior 行为)。C:\ISMSCleanDesktop\DesktopBkup_Tue10-22-2013\AgilityNewsService\AgilityNewsService\AgilityNewsService\clsDataware_MySQL.vb:line 48 中的 CreateDatatable(String SqlQuery, String strTable, String OrderbyField)

如何解决上述错误?

4

0 回答 0