hey,
im wondering what is the best way to go about creating queries...
my program.. i am creating a staff search program, i have craeted my databse and have included queries in access. but imnot sure how to call them in vb.net wondering if anyone can help me on that...
the alternative is i have made a query in vb.net
select Forname, surename, role, telephone, department
from Employees
Where (Forename=?) AND (Surname=?)
OR
(Forname=?) and (?=")
OR
(Surname=?) and (?=")
OR
(?=") and (?=")

and then im my code i have _search results=me.employees_tableAdapter.GetDataBy(me.forenameTextBox.Text, me.SurnameTextBox.Text)
i get this error message Argument not specified for Paramter 'Surname2' of 'Public Overridable Overloads Function GetDataBy (Forename as string, surname as string, forname1 as string, surname1 as string, surname2 as string) as companydataset.employeesdatatable

does anyone know where im going wrong and how to fix it?

Dani AI

Generated

Short diagnosis: the TableAdapter method the designer generated expects one argument for every parameter placeholder in your query. That is why is right — your call supplies only two values but the generated GetDataBy signature requires more. The extra parameters come from every question-mark placeholder you left in the Access query.

Practical fixes:

  • Keep the generated method: call it with all required arguments (for unused criteria pass an appropriate neutral value such as an empty string or DBNull.Value, matching the column type). Check the exact parameter order and names in the DataSet designer or the generated Designer file before calling.
  • Reduce the number of placeholders in the query so it exposes just the inputs you want (edit the query in the DataSet designer or in Access). Make blank inputs behave like “match anything” in the SQL so you only need two parameters.
  • Prefer building the WHERE clause in code: assemble criteria only for non-empty search boxes, add parameters in that same order, then run the query with a DataAdapter. This is the most flexible and avoids unused placeholders entirely; always use parameters (not string concatenation) to prevent injection.

Debug tips and cautions: OleDb/Access parameter placeholders are positional, so order matters. Open the DataSet designer or Object Browser to see the exact GetDataBy signature if unsure. When passing “no value” for a parameter, use DBNull.Value where your provider expects SQL NULL. If switching to dynamic SQL, keep parameter assignment and placeholder order consistent.

Acknowledging : creating a DataAdapter/DataSet and controlling the SQL from code is a solid approach for flexible searching and will eliminate the surprise of auto-generated multi-parameter methods.

Recommended Answers

All 2 Replies

hi
firstly u need to creat a data adapter and a dataset and a string sql

Looks like there's no overloaded version of the GetDataBy function that takes only 2 parameters(which is what you're trying to give it).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.