class无法编入索引,因为它没有默认属性

时间:2015-03-09 15:09:51

标签: visual-studio-2010

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click

    MySqlConn = New MySqlConnection
    MySqlConn.ConnectionString = "Server = Localhost; database = venuesdb; user id = root; Password = "

    Dim SQLDataAdapter As New MySqlDataAdapter
    Dim DatabaseDatSet As New DataTable
    Dim Bindsource As New BindingSource
    Dim Command As MySqlCommand


    Try
        MySqlConn.Open()
        Dim Query = "Select * From venuesdb.Event "
        Command = New MySqlCommand(Query, MySqlConn)
        SQLDataAdapter.SelectCommand = Command()
        SQLDataAdapter.Fill(DatabaseDatSet)
        Bindsource.DataSource = DatabaseDatSet
        DataGridView1.DataSource = Bindsource
        SQLDataAdapter.Update(DatabaseDatSet)
        MySqlConn.Close()

    Catch ex As Exception
        MessageBox.Show(ex.Message)

    End Try
    MySqlConn.Dispose()
End Sub

它说“Class'Mysql.Data.MySqlClient.MySqlCommand无法编入索引,因为它没有默认属性。”

问题是什么?

1 个答案:

答案 0 :(得分:1)

摆脱Command上的parens。

SQLDataAdapter.SelectCommand = Command

parens表示函数调用(或索引属性),而不是在这种情况下你想要的赋值。