0

嘿伙计们,我遇到了一个问题对象引用未设置为对象的实例。我是一个完整的初学者,所以任何说明/解决方案将不胜感激。

导入 System.Data.SqlClient 导入 MySql.Data.MySqlClient

Public Class Form1



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)      Handles MyBase.Load
    Dim connectionstring As String
    Dim commandtext As String
    Dim da As MySqlDataAdapter
    Dim table As DataTable
    commandtext = "select * From student"
    connectionstring = "Server=*****;Database=Harry;Uid=****;Pwd=****;Allow Zero Datetime=True;"


    Try
        da = New MySqlDataAdapter(commandtext, connectionstring)
        table = New DataTable
        da.Fill(table)
        DataGridView1.DataSource = table

    Catch ex As Exception
        MsgBox(ex.ToString)



    End Try
    Dim ds As New DataSet
    da = New MySqlDataAdapter
    da.Fill(ds, "student")


    DataGridView1.DataSource = ds.Tables("student")


End Sub


Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    ds.Tables("student").DefaultView.RowFilter = "student_id LIKE '%" & TextBox1.Text & "%' OR name LIKE '%" & TextBox1.Text & "*'"

End Sub

结束类

4

1 回答 1

1

在我看来,您的问题是 ds 的声明。

当您打算在多个地方使用它时,请尝试将其声明为全局变量。我认为您声明它的方式没有任何问题,只需将“Dim ds As New DataSet”行放在您的类中但在加载事件上方。

于 2012-10-10T12:17:21.617 回答