1

I am using ado.net to access sql server I have costum Stored Procedure I am executing it using ado.net :

SqlCommand command = new SqlCommand("Custom",con);

and i am sending the parameters like this :

 command.Parameters.Add(new SqlParameter("@Parm1",SqlDbType.Int,0,"Parm1"));

            command.Parameters.Add(new SqlParameter("@Parm2",SqlDbType.Int,0,"Parm2"))

it dose not work and it did not give me an error as well it is the first time to work without DAL generator

2 Answers 2

1

Please, use this pattern:

SqlCommand command = new SqlCommand("nameOfMyStoredProcedure", mySqlConnectionObject);  
command.CommandType = CommandType.StoredProcedure;  
command.Parameters.Add("@ID", SqlDbType.Int);  
command.Parameters["@ID"].Value = customerID;
Sign up to request clarification or add additional context in comments.

2 Comments

Last 2 lines can be combined to command.Paramters.Add("@ID", SqlDbType.Int).Value = customerID;
Personally I like to create the SqlParameters as separate objects and then add them after the command string (at the top of the method) it becomes much easier to read the code if you see the command string and parameters before you dive into the code that just sets up sql statements
1

to make it work add this line before set the params :

command.CommandType = CommandType.StoredProcedure;

and set the params using :

 command.Parameters[0].Value=4;

 command.Parameters[1].Value=2;

:)

2 Comments

My fault :( I have debug the code a lot but i did not search enough I thought that there is something wrong but not something missing :(
@ your service but search enough before asking and it happens with me a lot :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.