Click here to Skip to main content
15,310,056 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I've got a set of unique IDs that belong to Users table, eg. 1478, 8906, 4677, etc. Now how do I get a DataSet back with full record set of these users using DataAdapter?

I tried following which returns null, unfortunately. (DataSet's query builder)

SELECT  Col1, Col2, id
FROM   Table1
(CAST(id AS NVarchar(20)) IN (@param))

Code Behind:

Engineers.SM_UsersDataTable _dtUsers = new Engineers.SM_UsersDataTable();
EngineersTableAdapters.SM_UsersTableAdapter taUsers = new EngineersTableAdapters.SM_UsersTableAdapter();
String param = "123,124,125";
_dtUsers = taUsers.GetDataByStringedApprovals(param);

Am I doing something wrong here?


I have a set of unique IDs that I put into string, I need to use Table Adapter to query the full record set of these IDs.

I hope I make some sense.
Updated 24-Apr-12 2:50am
Rahul Rajat Singh 24-Apr-12 8:32am
Not clear. please elaborate.
cUbeindaclUb 24-Apr-12 9:11am
1) GetDataByStringedApprovals(@param) is a query saved in DataSet.
2) The SQL Statement is above but if more than one id is passed, it returns NULL
3) I need to pass these IDs and compare each record against IDs in passed @param string

Have you tried?

SELECT  Col1, Col2, id
FROM   Table1
id IN (@param))
cUbeindaclUb 24-Apr-12 9:31am
This solution throws following exception: "Input string was not in correct format."
Please note that id is int and @param is string
Subinal 24-Apr-12 9:59am
Check this out.
The solution I found is quite simple, this works like a charm and there's no need for sps or other functions;


SELECT whatever 
    FROM whatever
    WHERE (PATINDEX('%''' + CAST(id AS Varchar(20)) + '''%', @param) > 0)


String param = "'''1234'',''4567'''";
dataTable1 = tableAdapter1.getYourValues(param);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900