Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi all,

i have two field in table city,country.
i have two textboxes in form.
i want to use all textboxes as search like...

if i write

city : new Country : unite

or
city : york Country : uni


in textbox and then click on search so result should be...

new york, united state.



I tried...
VB
ss = "select * from Master where city like'%" + txtCity.Text + "%' and country like'%" + txtCountry.Text + "%'"
Posted
Updated 29-Jul-14 18:07pm
v2
Comments
OriginalGriff 29-Jul-14 7:54am    
And? What happened?
[no name] 29-Jul-14 8:14am    
not search proper, it's display only 2 data but there are more then 2
OriginalGriff 29-Jul-14 8:20am    
Which ones did it show, and which did it ignore?
BTW: You shouldn't do it like that - you leave yourself wide open to SQL Injection.
[no name] 29-Jul-14 8:28am    
i have seven data with new york city and united state country.
it shows only 4 data.
OriginalGriff 29-Jul-14 8:36am    
No, that doesn't help.
Show me the actual rows complete with data and indicate which it finds.
Remember, I can't see your screen! :laugh:

Use parameterized query to prevent sql injection and it will also save you a lot of syntax mess:
ss = "select * from Master where city like @city and country like @country"; 
cmd.Parameters.AddWithValue("@city", "%" + txtCity.Text +"%");
cmd.Parameters.AddWithValue("@country", "%" + txtCountry.Text +"%");

read more: sqlcommand.parameters[^]
 
Share this answer
 
try this.. :)

C#
"select * from Master where city like '%" + txtCity.Text + "%' and country like '%" + txtCountry.Text + "%'"; 
 
Share this answer
 
v2
Comments
OriginalGriff 29-Jul-14 8:08am    
Reason for my vote of one: your "solution" is the same (baring a few irrelevant spaces) as the sample text the OP provided.

Not a solution.
[no name] 29-Jul-14 8:51am    
it's works
Nirav Prabtani 29-Jul-14 8:56am    
Than why don't you mark as solved??
Nirav Prabtani 29-Jul-14 8:57am    
nopp i think you should look into it.. :)
CHill60 30-Jul-14 6:25am    
Reason for my vote of 3 - it works but you would have been better off explaining to the OP that they needed that space after each "like". You might have avoided the downvotes as well!
I also can't see the point of the extra string concatenation when "select * from Master where city like '%" + txtCity.Text + "%' and country like '%" + txtCountry.Text + "%'"; works just as well.
VB
ss = "select * from Donator where sname like @sname and city like @city and atpo like @atpo and taluka like @taluka and dist like @dist and pin like @pin" & _
     " and letter like @letter and notes like @notes and other like @other" ' and email like @email"
com = New OleDbCommand(ss, con)
com.Parameters.AddWithValue("@sname", "%" + TextBox12.Text + "%")
com.Parameters.AddWithValue("@city", "%" + TextBox13.Text + "%")
com.Parameters.AddWithValue("@atpo", "%" + TextBox14.Text + "%")
com.Parameters.AddWithValue("@taluka", "%" + TextBox15.Text + "%")
com.Parameters.AddWithValue("@dist", "%" + TextBox16.Text + "%")
com.Parameters.AddWithValue("@pin", "%" + TextBox17.Text + "%")
com.Parameters.AddWithValue("@letter", "%" + TextBox19.Text + "%")
com.Parameters.AddWithValue("@notes", "%" + TextBox20.Text + "%")
com.Parameters.AddWithValue("@other", "%" + TextBox21.Text + "%")

con.Open()
dr = com.ExecuteReader()
While dr.Read
    x = DataGridView1.Rows.Add(+1)

    DataGridView1.Rows(x).Cells(0).Value = dr(0)
    DataGridView1.Rows(x).Cells(1).Value = dr(2)
    DataGridView1.Rows(x).Cells(2).Value = dr(1)
    DataGridView1.Rows(x).Cells(3).Value = dr(3)
    address = dr(4) + ", " + dr(5) + ", " + dr(6) + ", " + dr(7) + ", " + dr(25) + ", " + dr(8) + ", " + dr(9) + ", " + dr(10)
    DataGridView1.Rows(x).Cells(4).Value = address

    DataGridView1.Rows(x).Cells(5).Value = dr(11)

    address1 = dr(12) + ", " + dr(13) + ", " + dr(14) + ", " + dr(15) + ", " + dr(26) + ", " + dr(16) + ", " + dr(17) + ", " + dr(18)

    DataGridView1.Rows(x).Cells(6).Value = address1

    DataGridView1.Rows(x).Cells(7).Value = dr(19)
    DataGridView1.Rows(x).Cells(8).Value = dr(20)
    DataGridView1.Rows(x).Cells(9).Value = dr(21)
    DataGridView1.Rows(x).Cells(10).Value = dr(22)
    DataGridView1.Rows(x).Cells(11).Value = dr(23)
End While
con.Close()
 
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