Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sql = "SELECT id,name,rptdate FROM Report where name like '%" & txtSearch.Text & "%' or id=" & txtSearch.Text

VB
If con.State = Data.ConnectionState.Open Then con.Close()
      Dim adapter As New OleDbDataAdapter(sql, con)
      adapter.Fill(dt)

if i run the code is shows "No value given for one or more required parameters." Error message.
Posted

Are you sure your query is correct?
Because you are passing same values to both conditions in where clause
i.e name & id conditions, both have same values.
 
Share this answer
 
Comments
sankar guru 16-Sep-10 7:47am    
yes, i get the input from one textbox for both.
nagendrathecoder 16-Sep-10 7:55am    
Debug your application, check the value of sql string and run it on sql server and see what is happening.
Hi,

If the "ID" column is characted based, then use single quotes (') in search condition

"SELECT id,name,rptdate FROM Report where name like '%" & txtSearch.Text & "%' or id= '" & txtSearch.Text & "'"

This may help you. Try it

Regards,
Suresh
 
Share this answer
 
v2
Comments
sankar guru 16-Sep-10 7:45am    
id is numeric,thats why i use double quotes
if delete after or condition its working well ?
from your code block you are testing the connection state. if its open your closing it!

If con.State = Data.ConnectionState.Open Then con.Close()
      Dim adapter As New OleDbDataAdapter(sql, con)
      adapter.Fill(dt)



I would debug your code put in break points and make sure SQL is as expected, and connection object etc are valid and not closed

dbadapter MSDN further reading if required
 
Share this answer
 
The error you are getting often comes when you do not pass your parameters properly while calling a stored procedure.

A better way of doing this is through a parameterized query

SELECT id,name,rptdate FROM Report where name like %@name% OR ID like %@ID%

Then add parameters to your parameter collection of the command object. Set the value of the parameters to the text property of your text box.

Hope this helps
 
Share this answer
 
Comments
Simon_Whale 16-Sep-10 8:56am    
he's creating dynamic SQL inside his application.

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