Click here to Skip to main content
15,888,020 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
If CON.State = ConnectionState.Closed Then
            CON.Open()
            DA = New OleDbDataAdapter("SELECT [voucher],[note],[dr],[cr],[da] FROM [ledger] WHERE cust-name=@1 AND da BETWEEN da=@1 AND da=@2", CON)
            DA.SelectCommand.Parameters.AddWithValue("@1", TextBox1.Text)
            DA.SelectCommand.Parameters.AddWithValue("@2", DateTimePicker1.Value.Date)
            DA.SelectCommand.Parameters.AddWithValue("@3", DateTimePicker2.Value.Date)
            Try
                DS = New DataSet
                Panel1.Hide()
                DA.Fill(DS, "ledger")
                DataGridView1.DataSource = DS.Tables("ledger")
            Catch ex As Exception
                MsgBox(ex.Message)
                Panel1.Show()
            End Try
        End If
        CON.Close()
        DA.Dispose()


What I have tried:

i want to filter by name and date range
Posted
Updated 10-Sep-20 7:39am

1 solution

Why are you using one parameter twice, and one not at all?
SQL
WHERE cust-name=@1 AND da BETWEEN da=@1 AND da=@2", CON)

I assume you meant:
SQL
WHERE cust-name=@1 AND da BETWEEN @2 AND @3", CON)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900