472,373 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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,eggs";
strSql += " AND ingredients IN @pIngredients";
string[] myList = ingredients.Split(',');
sda.SelectCommand.Parameters.AddWithValue("@pIngre dients", myList);

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

Oct 25 '07 #1
4 7432

"jayv" <ja**@discussions.microsoft.comwrote in message
news:80**********************************@microsof t.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,eggs";
strSql += " AND ingredients IN @pIngredients";
string[] myList = ingredients.Split(',');
sda.SelectCommand.Parameters.AddWithValue("@pIngre dients", myList);

the error is: System.ArgumentException: 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,eggs";
strSql += " AND ingredients IN @pIngredients";
string[] myList = ingredients.Split(',');
sda.SelectCommand.Parameters.AddWithValue("@pIngre dients", myList);

the error is: System.ArgumentException: 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,eggs";

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

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

"jayv" <ja**@discussions.microsoft.comwrote in message
news:80**********************************@microsof t.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,eggs";
strSql += " AND ingredients IN @pIngredients";
string[] myList = ingredients.Split(',');
sda.SelectCommand.Parameters.AddWithValue("@pIngre dients", myList);

the error is: System.ArgumentException: 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
by: Maksim Chepel | last post by:
Just what the subject says. Thanks a lot!
3
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...
9
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...
2
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...
5
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...
3
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...
0
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...
5
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...
3
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...
6
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.