473,684 Members | 3,054 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do i supply a list to an SQL "IN" list via parameters?

The best way to explain it, is to show you what i "thought" should work and
hope that you can show me a way to make it work please and thanks...

string ingredients = "pepper,salt,eg gs";
strSql += " AND ingredients IN @pIngredients";
string[] myList = ingredients.Spl it(',');
sda.SelectComma nd.Parameters.A ddWithValue("@p Ingredients", myList);

the error is: System.Argument Exception: No mapping exists from object type
System.String[] to a known managed provider native type.

Oct 25 '07 #1
4 7496

"jayv" <ja**@discussio ns.microsoft.co mwrote in message
news:80******** *************** ***********@mic rosoft.com...
The best way to explain it, is to show you what i "thought" should work
and
hope that you can show me a way to make it work please and thanks...

string ingredients = "pepper,salt,eg gs";
strSql += " AND ingredients IN @pIngredients";
string[] myList = ingredients.Spl it(',');
sda.SelectComma nd.Parameters.A ddWithValue("@p Ingredients", myList);

the error is: System.Argument Exception: No mapping exists from object type
System.String[] to a known managed provider native type.
You can't pass an array to SQL Server as some kind of parameter that I know
about. A manager provider is anyone that makes the DLL/Namespace for data
access to a database, like MS SQL Server, Oracle, Sybase, etc, etc.

Mylist is a string array. The best you can do is pass it as one delimited
string into a Stored Procedure, and you do a for loop or something to
extract the delimited data in the string inside the SP.

This is about as close as I am going to get for Native Types for you.

http://msdn2.microsoft.com/en-us/lib...2k(VS.80).aspx

Oct 25 '07 #2
jayv wrote:
The best way to explain it, is to show you what i "thought" should
work and hope that you can show me a way to make it work please and
thanks...

string ingredients = "pepper,salt,eg gs";
strSql += " AND ingredients IN @pIngredients";
string[] myList = ingredients.Spl it(',');
sda.SelectComma nd.Parameters.A ddWithValue("@p Ingredients", myList);

the error is: System.Argument Exception: No mapping exists from object
type System.String[] to a known managed provider native type.
http://www.sommarskog.se/arrays-in-sql.html

Andrew
Oct 26 '07 #3
So ... you want the additional classe to be executed as if it were

and ingredients in ('pepper','salt ','eggs')

therefore you need to build a string that looks like:

" and ingredients in ('pepper','salt ','eggs')"

To get the puncuation right you can use a technique like:

string ingredients = "pepper,salt,eg gs";

strSql += String.Format(" and ingredients in ('{0}')",
ingredients.Spl it(',').Join("' ,'"));

Then you just have to remember to assign strSql to the CommandText property
of sda.SelectComma nd.

"jayv" <ja**@discussio ns.microsoft.co mwrote in message
news:80******** *************** ***********@mic rosoft.com...
The best way to explain it, is to show you what i "thought" should work
and
hope that you can show me a way to make it work please and thanks...

string ingredients = "pepper,salt,eg gs";
strSql += " AND ingredients IN @pIngredients";
string[] myList = ingredients.Spl it(',');
sda.SelectComma nd.Parameters.A ddWithValue("@p Ingredients", myList);

the error is: System.Argument Exception: No mapping exists from object type
System.String[] to a known managed provider native type.
Oct 26 '07 #4
danger; this risks injection and doesn't allow query-plan re-use.
The blog that Andrew cited gives much better solutions to this
problem, along with other information.

Marc
Oct 26 '07 #5

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

Similar topics

2
1728
by: Maksim Chepel | last post by:
Just what the subject says. Thanks a lot!
3
42059
by: karthik | last post by:
Does anybody know what is the limit for the number of values one can have in a list of expressions (to test for a match) for the IN clause? For example, SELECT au_lname, state FROM authors WHERE state IN ('CA', 'IN', 'MD') Is there a limit in the number of expressions that can be included in the list to check for a match to STATE? I know this is a bad example as
9
2197
by: Emanuele Aina | last post by:
I have some code which does a lot of "in" on lists containing objects with no __eq__ defined. It all goes fast until I add the __lt__() method: then I have a slowdown comparable to the one I get using the overridden __eq__, while the __lt__ method is never called. Someone can explain me why?
2
8438
by: Rico | last post by:
Hello, Is there any way to get rid of or replacing the error message that pops up when you enter a combo box item that isn't in the list? I've tried using the Not In List event, but there is still an Access error that is raised. Any ideas? Thanks! Rick
5
6122
by: krwill | last post by:
I'm trying to automate a combo box to add a record to the source table if it's "Not In List". I've tried many different examples and none have worked. Combo Box Name = Combo24 Source Table Name = TblHandler Source Field Name = HandlerLoginID (key column = HandlerID which is an autonumber) Thanks
3
5418
by: delirman49 | last post by:
Hello, Sorry for my english. This is my problem : I must create for a great french company a webmethod with 2 "in" parameters. The first is an object, no problem. The second must be a "DataHandler". The company have a java client which send to my webmethod this 2 parameters. The java client send to the webservice a file (pdf, doc or other) and my webmethod save it on hard drive.
0
8625
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be anything from a short integer value to a complex struct type, also has a pointer to the next node in the single-linked list. That pointer will be NULL if the end of the single-linked list is encountered. The single-linked list travels only one...
5
1423
by: Muzammil | last post by:
i have problem with this operator "+" in doubly circular link list.(i think i have problem with return type). error is of instantiate error.(mean type dismatch) if any one can help me please reply. template <class T> DoublyCircularLinkList<TDoublyCircularLinkList<T>:: operator + (const DoublyCircularLinkList& rhs) { if (head==0 && rhs.head==0) {
3
2182
by: =?ISO-8859-1?Q?Andreas_M=FCller?= | last post by:
Hi! (Python 2.2.3 if this is relevant :-) I have a list of objects with, lets say, the attributes "ID", "x" and "y". Now I want to find the index of list element with ID=10. Of course I can loop through the list manually, but is there a construct like
6
6739
by: vanlanjl | last post by:
I cannot get the not in list event to work right. On my form I have a combo box named "cboChargeCode" I have a table named "tblChargeCode" I would like it so when you enter a value into the cbohargeCOde that is not listed it will alert you and ask you if you would like to add such item. My code
0
8568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8504
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9043
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8922
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8771
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4519
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2934
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2195
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.