thankssUse SqlCommand like this:
YourCommandName = New SQLCommand("YourStoredProcedureHere",YourConnection)
YourCommandName.CommandType = CommandType.StoredProcedureYou can also add parameters to the SqlCommand.|||got it.thankss
thankssUse SqlCommand like this:
YourCommandName = New SQLCommand("YourStoredProcedureHere",YourConnection)
YourCommandName.CommandType = CommandType.StoredProcedureYou can also add parameters to the SqlCommand.|||got it.thankss
I have created a stored procedure only with an insert statement in sql server 2005.
How can i call this stored procedure through code in ASP.NET page using vb.
i want to pass one parameter that comes from a text box in asp.net page.
my emailid is:g12garg@.yahoo.co.in pls reply.
Thank you
Gaurav
dim conn as new sqlconnection("Your connection string here")
dim cmd as new sqlcommand("Your stored procedure name here",conn)
cmd.CommandType=CommandType.StoredProcedure
cmd.parameters.add("@.Your parameter name here",Your parameter type here).value=your parameter value here
conn.open
cmd.executenonquery
conn.close
|||
Thank you.
Now i want to encrypt this passing value in the stored procedure. i want the encryption to be done in the stored procedure using symmetric key. So do i need to convert this value to varbinary in the stored procedure. or only in the table?
I would like to know what are the ways to call a parameterized stored procedure within a loop in ASP.NET.
Scenario:
I have a loop through a dataSet and for each record I am going to execute a stored procedure to insert data in many tables.
I can not use the following syntax:
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "dbo.storedprocedurename"
With cmd
.Parameters.Add(New SqlClient.SqlParameter("@.param1", paramValue1))
.Parameters.Add(New SqlClient.SqlParameter("@.param2", paramValue2))
End With
What are the other ways to execute the parameterized stored procedures within a loop in ASP.NET?
Thanks,
Carlos
As far as i know u can not execute stored procedure with out"CommandType.StoredProcedure"property.
other wise just write a insert query (that also needs parameters) thru loop and execute them by using execute non query
|||I agree:
The problem is not the following lines:
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "dbo.storedprocedurename"
The problem is the following lines:
With cmd
.Parameters.Add(New SqlClient.SqlParameter("@.param1", paramValue1))
.Parameters.Add(New SqlClient.SqlParameter("@.param2", paramValue2))
End With
I was trying to find the alternative syntax to the lines above and the solution is to use:
With cmd
.Parameters.Add("@.param1", DbDataType.Varchar())
.Parameters.Add("@.param2", DbDataType.Varchar())
End With
Thanks,
Carlos
|||You said you are going to execute the sproc in a loop, so be careful to clear the parameter collection after executing the sproc, otherwise the parameter's collection in your command object will keep on increasing and on the second loop itself it'll give you and error. This is not needed if you are nullifying and re-setting the command object every time.
Hope this will help.
|||hi,
As you said you are using for loop for executing stored procedure, so clear the parameters collection after call execute nonquery method like this
cmd.ExecuteNonQuery();
lCmd.Parameters.Clear();
Hope it helps