this is my sp
UPDATE Con
SET Category1code =c1.Category1Name, Category2Code=c2.Category2Name
FROM Contacts Con
INNER JOIN Category1 As c1
ON Con.Category1Code = c1.Category1Code
Inner Join Category2 As c2
ON Con.Category2Code = c2.Category2Code
just i want write above sp into simple query like
SqlConnection Con=new SqlConnection();
SqlCommand cmd=New SqlCommand("how to write above sp here",con);
please give me solution
thanx in advance.

Pradip PandeyRank #452 · 5.6K reputationPosted Mar 19, 2013, 2:32 AM EDT
Hi Use following code string sqlQuery = "UPDATE Con " + "SET Category1code = c1.Category1Name, Category2Code = c2.Category2Name " +"FROM Contacts Con " + "INNER JOIN Category1 As c1 " + "ON Con.Category1Code = c1.Category1Code " + "Inner Join Category2 As c2 " + "ON Con.Category2Code = c2.Category2Code "; SqlConnection Con=new SqlConnection();SqlCommand cmd=New SqlCommand(sqlQuery ,con); Hope it will help.Ajinkya Ban32 reputationPosted Mar 19, 2013, 2:37 AM EDT
Pradip PandeyRank #452 · 5.6K reputationPosted Mar 19, 2013, 2:47 AM EDT
Please mark it as Accepted Answer, if it really helped you.
Hope it will help.
Ajinkya Ban32 reputationPosted Mar 19, 2013, 2:51 AM EDT
Vishal GilbileRank #268 · 9.4K reputationPosted Mar 19, 2013, 3:07 AM EDT
You just need to call the procedure following is the way for calling.
SqlConnection con=new SqlConnection("Your Connection string over here");
SqlCommand cmd=new SqlCommand("ProcedureName",con);
cmd.CommandType=CommandType.StoredProcedure;
//if your procedure accepts parameter you need to add it for instance if my proc accepts //a parameter name @name I will add it in the following way.
cmd.Parameter.AddWithValue("@name","value");
// Rest of the execution is same what we do for single line query.
With Regards,
Vishal Gilbile
Pradip PandeyRank #452 · 5.6K reputationPosted Mar 19, 2013, 3:21 AM EDT
This is because previously you have updated Category1code & Category2code with categoryname.
Hope it will help.
Ajinkya Ban32 reputationPosted Mar 19, 2013, 3:32 AM EDT
Ajinkya Ban32 reputationPosted Mar 19, 2013, 3:32 AM EDT