Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send parameters to SP without using AddParameter 1

Status
Not open for further replies.

JOBARAM

Programmer
May 25, 2002
52
IL
Hi,
I used to work with ADO connecting to my SQL server and to activate a stored procedure ('Temp_SP') that expect few params i have done the following:
#######
.......
str= "exec Temp_SP Param1_Val,Param2_val"
//executing the SP...
oConn.Execute SQLQuery, , adExecuteNoRecords
########

Now I'm using C# under .Net platform.
How can I do the same without using AddParameter as follows:
###########
SqlStoredProcedure sp = new SqlStoredProcedure(SP_Name,
Connection.SqlConnection);

sp.AddParameter("@Filestr", SqlDbType.VarChar, 256,
ParameterDirection.Input, FilePath.ToString() );

sp.ExecuteNonQuery ();
############

If I have many parameters It will be easier for me to add all the parameters in a string instead of Adding parameters as I have done above. Can it be done?

Thanks
 
It looks like in the examples, you're not returning a recordset? Well you can easily still execute a string with your exec statement in .Net You should be able to use a SqlCommandObject to execute that string. Now if you want to return the results to .Net, I don't know if its going to have a problem with it or not. What I mean by that is using it say, as the "select command" for a dataAdapter probably won't work.
 
Thanls RiverGuy for your reply,
I have tried to use Sql Command ExecuteNonQuery() and to run
the string "exec SP_name Param1_Val,Param2_val,Param_3...."
But it doesn't work.
I do not want to return a recordset.
All I want is to activate SP_name stored procedure and to send it the input parameters as in the string.
Can you give me an exapmle how to do that?
Thanks a lot.
Yossi
 
Sure. The first way I always troubleshoot things like this is to take the simple approach--using form designed objects to troubleshoot. I created a SqlConnection and SqlCommand object and placed them on the form. Now for the properties of the SqlCommand, under Connection, make sure you've got your SqlConnection listed. CommandText, type your text in there.....Command type is text.

On your form load, make sure to open the connection.

I placed a command button on the form and did a "cmd1.ExecuteNonQuery()". I tried a simple SP, using 1 parameter for this. So, if you're using hand-coded connections and commands, give it a try first with objects on your form....then try changing the properties in code, to change yoru stored procedure. BTW, it worked perfect for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top