VB动态sql查询不起作用

时间:2016-02-23 08:17:10

标签: vb.net

Public Class Form5

    Dim CrystalReportViewer1 As Object

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If TextBox1.Text = "thulasi" Then
            Form3.Show()
        Else
            MsgBox("Incorrect password ! Try again", MsgBoxStyle.OkOnly, "Thulasi-Restaurent")
            Exit Sub
        End If
        Me.Close()


        Dim ds As New DataSet
        Dim str As String
        str = "select * from billall where bdate between  #" & DateTimePicker1.Value.Date & "# and #" & DateTimePicker2.Value.Date & "# order by indate"

        Cn.Open()
        Dim adap As New OleDbDataAdapter(str, Cn)

        adap.Fill(ds, "billall")
        Dim doc1 As New ReportDocument
        doc1.Load("D:\billing\DuraiRestaurent\CrystalReport2.rpt")
        doc1.SetDataSource(ds)
        CrystalReportViewer1.CrystalReport2.ReportSource = doc1
        Cn.Close()
    End Sub

End Class

当尝试执行OleDBException错误时:"没有给出一个或多个必需参数的值"。你能帮忙吗?

1 个答案:

答案 0 :(得分:0)

当您收到此错误时,表示Access Engine无法正确找到您的一个或多个列名或整个表名。

对于OleDbDataAdapter我会说你应该像这样使用它(例子):

 String command = "SELECT movieId, name, headActor, Director, ReleaseDate, lenghtMin " &
          "FROM Movies WHERE headactor =  ?"

 Dim adapter As OleDbDataAdapter = new OleDbDataAdapter(command, connectionString);
 adapter.SelectCommand.Parameters.AddWithValue("@p1", lastName)