Using stored procedures

yablonka

Member
Joined
May 19, 2003
Messages
14
Hello,

I created a stored procedure which receive a few parameters and inserts them into the DB according to some conditions,
BUT - Im very new to VB.NET, how do I call the store procedure at runtime and how do I pass the parameters???

Thank you,
 
The process is quite similar to executing a SQL statement.
Code:
Dim oConnection As SqlConnection = New SqlConnection()
Dim oConnection As SqlCommand = New SqlCommand()
Dim oDataReader As SqlDataReader
			
oConnection.Open()
			
oCommand.CommandType = CommandType.StoredProcedure
oCommand.CommandText = "storedProcedureName"
oCommand.Connection = oConnection

Dim oParameter1 As SqlParameter = oCommand.Parameters.Add("@iInteger", SqlDbType.Int)
oParameter1.Value = 1
			
oDataReader = oCommand.ExecuteReader()
			
While (oDataReader.Read())
	 If the stored procedure does not return rows "oDataReader" is unnecessary
	 and a call to "oCommand.ExecuteNonQuery()" or "oCommand.ExecuteScalar()"
	 should be used instead
End While
			
oDataReader.Close()
oConnection.Close()
 
Back
Top