Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i m little bit confuse that can we pass complete datatable or dataset to store procedure
and how to use it in store procedure.

amit jamwal
Posted

 
Share this answer
 
Comments
Amit Jamwal 2-Nov-12 1:40am    
thnx for ur reply...
but my prob is that i hav a table emp in which emp_code is there.Now i am uploading an exl file in which emp_code and amount is there. Wht i have to do is to first m filling a datatable from exl and after that i have to match those emp_code with my emp table.
and my exl file contains more than 7000 records and checking them one bye one in loop is time consuming so i m thinking to pass datatable to storproc and match there once...
any solution.....
 
Share this answer
 
v2
yes u can pass datatable to SP, but first u need to create a user-defined table type in SQL server, having same structure as datatable to be passed. For eg:
SQL
CREATE TYPE TypeName AS TABLE
(
	col1 int,
	col2 varchar(50)
)

then in SP parameter, use type "TypeName".

If u r using C#, while passing datatable to SP, use SqlDbType.Structured.
 
Share this answer
 
Comments
Amit Jamwal 2-Nov-12 2:45am    
Thnx for reply..
on google i found same example.
but in my store procedure following error is coming

parameter cannot be declared as readonly as it is not table value type
plz give the soln for abov prob.....
Gautam Raithatha 2-Nov-12 2:53am    
if u have created user defined type as Table, then it will not giv this type of error.

@ParamName TypeName READONLY

Here "TypeName" is table type so it should not give error:

CREATE TYPE TypeName AS TABLE
(
col1 int,
col2 varchar(50)
)

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



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