OleDBException 0x80040e10没有值给定

时间:2014-02-18 15:51:23

标签: vb.net oledb

当Textbox值为null时,第一部分正常工作。但是,当我尝试使用if语句的第二部分过滤搜索时,它会引发异常。

表var的设置方式是因为用户可以选择加载不同的表。

文本框字符串是搜索参数。

Public Class form1

    Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= .\Service.accdb ;")
    Dim da As New OleDbDataAdapter

 Private Sub getdata()
        Me.Refresh()

        Dim dt As New DataTable
        Dim cmd As New OleDbCommand
        Dim table As String = ComboBox1.Text.ToString
        Dim txt As String = TextBox1.Text.ToString

        If TextBox1.Text = Nothing Then

            con.Open()
            da.SelectCommand = New OleDbCommand("select * from [" & table & "] ;", con)
            con.Close()
        Else

            con.Open()
            da.SelectCommand = New OleDbCommand("select * from [" & table & "] where (External like '%" & txt & "%' or Internal like '%" & txt & "%' or Code like '%" & txt & "%');", con)
            con.Close()
        End If

        Try
            da.Fill(dt)
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

        DataGridView1.DataSource = dt

    End Sub
End Class

任何帮助都将不胜感激。

修改

似乎这段代码阻止它正确搜索,但没有它我无法保存到数据库..

    Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(da)
    builder.QuotePrefix = "["
    builder.QuoteSuffix = "]"

所以我假设我错过了这部分的参数?

0 个答案:

没有答案