Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have this filter and that is working perfect but I need also to add more filters like this
And kod Like '" & txttrfirma.Text & "%' order by datumdos,grupa,proizvod,firma"

how to do that?

What I have tried:

sql1 = "SELECT * FROM tblpromet WHERE datumdos BETWEEN ? AND ? "
da1 = New OleDb.OleDbDataAdapter(sql1, con)
da1.SelectCommand.Parameters.AddWithValue(" min", DateTimePicker1.Value)
da1.SelectCommand.Parameters.AddWithValue(" max", DateTimePicker2.Value)
da1.Fill(ds, " PrometBase" )
Posted
Updated 13-Sep-19 0:59am
Comments
ZurdoDev 3-Sep-19 15:14pm    
1. Don't concatenate your control values into your sql statement because you expose your db to be hacked.
2. What db is this? Is it Mysql?
3. Just add " AND " and then the other condition to what you already have. What is the problem?
MarkTJohnson 4-Sep-19 11:03am    
The question marks are the placeholders for the two Parameters.AddWithValue calls. They get done in sequential order. Oh, my bad, you weren't asking what the question marks were, you were asking questions.

1 solution

Quote:
I need also to add more filters like this
And kod Like '" & txttrfirma.Text & "%' order by datumdos,grupa,proizvod,firma"


All you need to do is to add another parameter
VB
sql1 = "SELECT * FROM tblpromet WHERE (datumdos BETWEEN ? AND ? ) AND (kod Like ?%);"
da1 = New OleDb.OleDbDataAdapter(sql1, con)
da1.SelectCommand.Parameters.AddWithValue(" min", DateTimePicker1.Value)
da1.SelectCommand.Parameters.AddWithValue(" max", DateTimePicker2.Value)
da1.SelectCommand.Parameters.AddWithValue(" kod", txttrfirma.Text)
da1.Fill(ds, " PrometBase" ) 


Note, that you can't add sort order through the parameters. You need to define order in your command:
VB
sql1 = "SELECT * FROM tblpromet WHERE (datumdos BETWEEN ? AND ? ) AND (kod Like ?%) ORDER BY  datumdos, grupa, proizvod, firma;"
 
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