2016-02-23 95 views
1
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时发生错误:“没有给出一个或多个所需参数的值”。你能帮我吗?VB动态SQL查询不起作用

+0

您正在使用什么数据库,SQL,ORAC; E,MySQL的等? –

+0

看起来像是一个ACCESS数据库。你能否确认字段“indate”是否是表billall上的有效字段? –

+0

您好kelly我在我的数据库indate,但无法找到问题无论如何,我已经通过创建一个新的查询访问数据库本身与表中的SQL查看选项,现在工作很好,谢谢你的答复。 –

回答

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)