473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Multiple Criteria in SQL setup problem with parameter order.

I have the following problem:
I have created the following SQL for my app. With the below shown code
(Example 1) I am able to retrieve the records I need into dataset
dsFind.

Now however I want to do another search as in Example 2, this doesnt
work and I get no records.

However if I switch around the order of the parameters as seen in
Example 3 I get my records after EfterNavn.

This makes it difficult to make an SQL with more criterias like:
SQLFindString = "SELECT PersonsInfo.* FROM PersonsInfo"
SQLFindString = SQLFindString & " WHERE (EfterNavn = ?) AND ([By] =
?)"

So my question what is wrong with my parameter addition to the
parameter collection. I cant believe it matters what the order is of
the parameter declarations. If anyone has any experience with this,
please post a reply.

Best regards,
Jesper Jensen
Example 3:
daPersons.SelectCommand.Parameters.Add("EfterNavn" , OleDbType.VarChar,
70).Value = EfterNavn
daPersons.SelectCommand.Parameters.Add("[By]", OleDbType.VarChar,
50).Value = By

Example 2:
SQLFindString = "SELECT PersonsInfo.* FROM PersonsInfo"
SQLFindString = SQLFindString & " WHERE (EfterNavn = ?)"

Example 1:
Dim SQLFindString As String = ""
Dim iniWhere As Boolean = False

SQLFindString = "SELECT PersonsInfo.* FROM PersonsInfo"
SQLFindString = SQLFindString & " WHERE ([By] = ?)"

OleDbSelectCommand1 = New OleDbCommand(SQLFindString)
daPersons.SelectCommand = OleDbSelectCommand1

OleDbSelectCommand1.Connection = DbCon
daPersons.SelectCommand.Parameters.Add("[By]", OleDbType.VarChar,
50).Value = By
daPersons.SelectCommand.Parameters.Add("EfterNavn" , OleDbType.VarChar,
70).Value = EfterNavn

daPersons.Fill(dsFind, "PersonsInfo")
datGrid.SetDataBinding(dsFind, "PersonsInfo")
Nov 20 '05 #1
3 1940
CT
When you use unnamed parameters (?) with OLEDB, the parameters must be added
in the order in which they're referenced in the SELECT statement. If you're
using the Sql Server .NET Provider, you can use named parameters in your
SELECT statements (I don't know what dat source you're using...).

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Jesper Jensen" <Je*****@post8.tele.dk> wrote in message
news:dc**************************@posting.google.c om...
I have the following problem:
I have created the following SQL for my app. With the below shown code
(Example 1) I am able to retrieve the records I need into dataset
dsFind.

Now however I want to do another search as in Example 2, this doesnt
work and I get no records.

However if I switch around the order of the parameters as seen in
Example 3 I get my records after EfterNavn.

This makes it difficult to make an SQL with more criterias like:
SQLFindString = "SELECT PersonsInfo.* FROM PersonsInfo"
SQLFindString = SQLFindString & " WHERE (EfterNavn = ?) AND ([By] =
?)"

So my question what is wrong with my parameter addition to the
parameter collection. I cant believe it matters what the order is of
the parameter declarations. If anyone has any experience with this,
please post a reply.

Best regards,
Jesper Jensen
Example 3:
daPersons.SelectCommand.Parameters.Add("EfterNavn" , OleDbType.VarChar,
70).Value = EfterNavn
daPersons.SelectCommand.Parameters.Add("[By]", OleDbType.VarChar,
50).Value = By

Example 2:
SQLFindString = "SELECT PersonsInfo.* FROM PersonsInfo"
SQLFindString = SQLFindString & " WHERE (EfterNavn = ?)"

Example 1:
Dim SQLFindString As String = ""
Dim iniWhere As Boolean = False

SQLFindString = "SELECT PersonsInfo.* FROM PersonsInfo"
SQLFindString = SQLFindString & " WHERE ([By] = ?)"

OleDbSelectCommand1 = New OleDbCommand(SQLFindString)
daPersons.SelectCommand = OleDbSelectCommand1

OleDbSelectCommand1.Connection = DbCon
daPersons.SelectCommand.Parameters.Add("[By]", OleDbType.VarChar,
50).Value = By
daPersons.SelectCommand.Parameters.Add("EfterNavn" , OleDbType.VarChar,
70).Value = EfterNavn

daPersons.Fill(dsFind, "PersonsInfo")
datGrid.SetDataBinding(dsFind, "PersonsInfo")

Nov 20 '05 #2
For me it works like this

daTEMPTEK.SelectCommand.Parameters.Add(New SqlParameter("@Name1",SqlDbType.Int))
daTEMPTEK.SelectCommand.Parameters.Add(New SqlParameter("@Name2",SqlDbType.Int))
daTEMPTEK.SelectCommand.Parameters("@Name1").Value = pVariable1
daTEMPTEK.SelectCommand.Parameters("@Name2").Value = pVariable2

hope this helps
greetz


Je*****@post8.tele.dk (Jesper Jensen) wrote in message news:<dc**************************@posting.google. com>...
I have the following problem:
I have created the following SQL for my app. With the below shown code
(Example 1) I am able to retrieve the records I need into dataset
dsFind.

Now however I want to do another search as in Example 2, this doesnt
work and I get no records.

However if I switch around the order of the parameters as seen in
Example 3 I get my records after EfterNavn.

This makes it difficult to make an SQL with more criterias like:
SQLFindString = "SELECT PersonsInfo.* FROM PersonsInfo"
SQLFindString = SQLFindString & " WHERE (EfterNavn = ?) AND ([By] =
?)"

So my question what is wrong with my parameter addition to the
parameter collection. I cant believe it matters what the order is of
the parameter declarations. If anyone has any experience with this,
please post a reply.

Best regards,
Jesper Jensen
Example 3:
daPersons.SelectCommand.Parameters.Add("EfterNavn" , OleDbType.VarChar,
70).Value = EfterNavn
daPersons.SelectCommand.Parameters.Add("[By]", OleDbType.VarChar,
50).Value = By

Example 2:
SQLFindString = "SELECT PersonsInfo.* FROM PersonsInfo"
SQLFindString = SQLFindString & " WHERE (EfterNavn = ?)"

Example 1:
Dim SQLFindString As String = ""
Dim iniWhere As Boolean = False

SQLFindString = "SELECT PersonsInfo.* FROM PersonsInfo"
SQLFindString = SQLFindString & " WHERE ([By] = ?)"

OleDbSelectCommand1 = New OleDbCommand(SQLFindString)
daPersons.SelectCommand = OleDbSelectCommand1

OleDbSelectCommand1.Connection = DbCon
daPersons.SelectCommand.Parameters.Add("[By]", OleDbType.VarChar,
50).Value = By
daPersons.SelectCommand.Parameters.Add("EfterNavn" , OleDbType.VarChar,
70).Value = EfterNavn

daPersons.Fill(dsFind, "PersonsInfo")
datGrid.SetDataBinding(dsFind, "PersonsInfo")

Nov 20 '05 #3
Thank You,
The sort order had to be synchronised with the SELECT statement as you
wrote. I was using OleDB dat Source (Access DB).

Best regards,
Jesper Jensen

"CT" <ca******@spammersgoawaydotnetservices.biz> wrote in message news:<uS**************@TK2MSFTNGP09.phx.gbl>...
When you use unnamed parameters (?) with OLEDB, the parameters must be added
in the order in which they're referenced in the SELECT statement. If you're
using the Sql Server .NET Provider, you can use named parameters in your
SELECT statements (I don't know what dat source you're using...).

--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Jesper Jensen" <Je*****@post8.tele.dk> wrote in message
news:dc**************************@posting.google.c om...
I have the following problem:
I have created the following SQL for my app. With the below shown code
(Example 1) I am able to retrieve the records I need into dataset
dsFind.

Now however I want to do another search as in Example 2, this doesnt
work and I get no records.

However if I switch around the order of the parameters as seen in
Example 3 I get my records after EfterNavn.

This makes it difficult to make an SQL with more criterias like:
SQLFindString = "SELECT PersonsInfo.* FROM PersonsInfo"
SQLFindString = SQLFindString & " WHERE (EfterNavn = ?) AND ([By] =
?)"

So my question what is wrong with my parameter addition to the
parameter collection. I cant believe it matters what the order is of
the parameter declarations. If anyone has any experience with this,
please post a reply.

Best regards,
Jesper Jensen
Example 3:
daPersons.SelectCommand.Parameters.Add("EfterNavn" , OleDbType.VarChar,
70).Value = EfterNavn
daPersons.SelectCommand.Parameters.Add("[By]", OleDbType.VarChar,
50).Value = By

Example 2:
SQLFindString = "SELECT PersonsInfo.* FROM PersonsInfo"
SQLFindString = SQLFindString & " WHERE (EfterNavn = ?)"

Example 1:
Dim SQLFindString As String = ""
Dim iniWhere As Boolean = False

SQLFindString = "SELECT PersonsInfo.* FROM PersonsInfo"
SQLFindString = SQLFindString & " WHERE ([By] = ?)"

OleDbSelectCommand1 = New OleDbCommand(SQLFindString)
daPersons.SelectCommand = OleDbSelectCommand1

OleDbSelectCommand1.Connection = DbCon
daPersons.SelectCommand.Parameters.Add("[By]", OleDbType.VarChar,
50).Value = By
daPersons.SelectCommand.Parameters.Add("EfterNavn" , OleDbType.VarChar,
70).Value = EfterNavn

daPersons.Fill(dsFind, "PersonsInfo")
datGrid.SetDataBinding(dsFind, "PersonsInfo")

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: googleboy | last post by:
I didn't think this would be as difficult as it now seems to me. I am reading in a csv file that documents a bunch of different info on about 200 books, such as title, author, publisher, isbn,...
5
by: Irfan | last post by:
Hi All, I am trying to create a report but having problem with the critiera selection logic, please help. I have the following fields date1 date2 date3
0
by: Greg Strong | last post by:
Hello All, In the past I've used a combo box with the 'row source' being an Access SQL union query to select "All" or 1 for only 1 criteria in a query. An example is as follows: SELECT 0 As...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
6
by: kcddoorman | last post by:
I built a select query filled with fields from multiple tables and queries. I have one field in this particluar query that will filter out a single order number. In the criteria box I put and that...
0
by: mmueller | last post by:
I am new to reporting services 2005 (reporting in Access for years and older versions of Reporting Services from time to time) and this is probably a dumb question... but I have no internal resources...
6
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate...
1
by: Bobby Edward | last post by:
Using Access db with VS2008 (ASP.NET/VB.NET).... On the INSERT command I get this error: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression. I haven't found a...
4
by: jvan2008 | last post by:
"Form1" combobox "cboModel" Row Source SELECT ., . FROM tblModel ORDER BY ; combobox "cboContactName" SELECT . FROM Query1 ORDER BY ;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.