Question How to execute a SQL Store proc

Joined
May 22, 2012
Messages
1
Programming Experience
Beginner
I am new bie in VB.net and i need to execute a SQL store proc usning vb.net. I think i am missing a something from the below code. Thanks in advance for your help. Please correct me where i went wrong.

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Cmd_Submit.Click

Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim adapter As New SqlDataAdapter
Dim ds As New DataSet

Dim RuleId As String
Dim Desc As String
Dim GrpId As String
Dim TSGLnk As String
Dim Severity As String

'Assinging all teh values from the input boxes.

RuleId = TextBox_RuleId.Text
GrpId = "6AF797D9-8C81-4564-97DD-1D28ECAD6FEB"
Desc = RichTextBox_Desc.Text
TSGLnk = RichTextBox_NewLnk.Text
Severity = "SEV B"

con.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=DBName;server=ServerName;Connect Timeout=30"
con.Open()

cmd.CommandText = "EXEC StoreProc @MonitoringRuleID = '" + RuleId + "', @Description = '" + Desc + "',@ManagementGroupID = '6AF797D9-8C81-4564-97DD-1D28ECAD6FEB',@TSGLink ='" + TSGLnk + "', @DefaultSeverity = 'Sev B'"

cmd.CommandType = CommandType.StoredProcedure 'Setup Command Type
cmd.Connection = con 'Active Connection


'cmd = New SqlCommand(sSQL, con)
adapter.SelectCommand = cmd
'adapter.Fill(ds)
adapter.Dispose()
cmd.Dispose()
con.Close()


End Sub
 
The CommandText should be just the name of the procedure. You change the CommandType to StoredProcedure and add the parameters to the command. For help with that last step, follow the Blog link in my signature and check out my post on Parameters In ADO.NET.
 
Back
Top