vb.net中sql命令无法转换为mysql命令的原因

vb.net中sql命令无法转换为mysql命令的原因,mysql,vb.net,Mysql,Vb.net,我目前正在将我的数据网格视图连接到数据库,但问题是我无法连接此错误:MySql.data.MySqlClient.MySqlCommand无法转换为System.data.SqlClient.SqlCommand 这是我的密码: Private Sub populateGird() Dim da As New SqlDataAdapter Dim ds As New DataSet Dim bs As New BindingSource

我目前正在将我的数据网格视图连接到数据库,但问题是我无法连接此错误:MySql.data.MySqlClient.MySqlCommand无法转换为System.data.SqlClient.SqlCommand

这是我的密码:

Private Sub populateGird()
        Dim da As New SqlDataAdapter
        Dim ds As New DataSet
        Dim bs As New BindingSource
        Try
            sqlC = New MySqlCommand("SELECT c_id, CONCAT(c_firstname, c_lastname), rank_name, c_bir_status, rank_basic_pay, rank_positional_allowance," &
                                    "rank_meal_allowance, ca_worth FROM tbl_crew, tbl_cash_advance, tbl_rank", conn)
            da.SelectCommand = sqlC '--> error is that sqlC
            da.Fill(ds)
            bs.DataSource = ds
            PayrollGrid.DataSource = bs
            da.Update(ds)
            conn.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            conn.Dispose()
        End Try
这是我在模块中的连接代码:

Imports MySql.Data.MySqlClient

Module Module1
Public conn As MySqlConnection

Public Sub connect()
    conn = New MySqlConnection
    conn.ConnectionString = "server=localhost;user=root;database=fat2x_payroll;pwd=;Convert Zero Datetime=True"

    Try
        conn.Open()
    Catch ex As Exception
        MsgBox(ex.Message)

    End Try
End Sub

End Module

将SqlDataAdapter的声明更改为MySQL的适当类型我猜是MySqlDataAdapter

Dim da As New SqlDataAdapter

错误消息非常清楚-您试图从不兼容的类型分配!SelectCommand的类型为System.Data.SqlClient.SqlCommand,因为您已将da定义为System.Data.SqlClient.SqlDataAdapter类型的变量。另一方面,您正在创建一个类型为MySql.Data.MySqlClient.MySqlCommand的变量,它是另一种类型,在尝试执行赋值时无法转换为SqlCommand

解决此问题的方法是将代码更改为使用MySql.Data.MySqlClient中相应的类,如下所示:

 Dim da As New MySqlDataAdapter

将命令更改为SQLCommand,或将SQLDataAdapter更改为MySQLDataAdapter