Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parameter query not working

Status
Not open for further replies.

hondaman2003

Programmer
Mar 3, 2008
202
US
I am trying to create a parameter query so I can make a search form. In my SQL I have the following command:

WHERE ([fieldName] LIKE '@AccountNumber')

When I run the query, it doesn't ask for the parameter. I see the tick marks in there but visual studio puts them in there automatically when I type the following:

LIKE @AccountNumber

Can you tell me why this is happening?
 
VB.Net is not a 4GL language. So your application is not going to create a form on the fly, display it to the user and prompt for a parameter. You have to code to ask for the parameter and you have to code to supply the query with the parameter.

Secondly, you don't need those single quotes.

Thirdly, there is no point in using LIKE unless you are using some sort of wildcard. Try something like this:

WHERE ([fieldName] LIKE @AccountNumber + '%')

The full code would look something like:
Code:
YourCommand.CommandText = "SELECT * FROM SomeTable WHERE ([fieldName] LIKE @AccountNumber + '%')"
YourCommand.Parameters.AddWithValue("@AccountNumber", InputBox("Enter an account number"))
 
You have a good point about using 'LIKE'. I will remove it as I want the user to type the entire account number not just the first part.

I already have a form with a textbox and search button in the toolstrip menu. I want the form to change its tableadapter with the following command:

Me.Credit_information_tableTableAdapter.FillByAccountNumber(Me.CreditsDataSet.Credit_information_table, tsSearchCriteria.Text)

This is not working. I believe I am following all the instructions according to MSDN. The only reason I wanted the query to ask me for the parameter is because a tutorial video show it happening when I run the query directly from the query builder.
 
I also understand that when viewing the dataset from the solution explorer when you are looking at the list of queries under a table, it should show the name of the query like this:

GetDataByFilterAccountNumber()

When there is a parameter, there should be something listed in the parentheses. Please correct me if I am wrong. I cannot get anything to appear in those parentheses.
 
Sorry, I don't use TableAdapters or other heavy abstractions of ADO.Net, so I'm not sure.
 
Do you have a link to a website or can you explain to me how you would do what I am trying to do?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top