Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello,

 

I created a stored procedure which receive a few parameters and inserts them into the DB according to some conditions,

BUT - I'm very new to VB.NET, how do I call the store procedure at runtime and how do I pass the parameters???

 

Thank you,

  • *Gurus*
Posted

The process is quite similar to executing a SQL statement.

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()

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...