Click here to Skip to main content
14,298,696 members
Rate this:
Please Sign up or sign in to 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 3 days ago
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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
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:
sql1 = "SELECT * FROM tblpromet WHERE (datumdos BETWEEN ? AND ? ) AND (kod Like ?%) ORDER BY  datumdos, grupa, proizvod, firma;"
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100