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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sub/Function that allows me to run various MSSQLServer 2008 stored procedures using vb.net

Status
Not open for further replies.

szoora

Programmer
Dec 23, 2014
3
UG
I am trying to run SQL SERVER 2008 stored procedure using VB.NET. I am able to connect fine but I do not want to write the code over again for every stored procedure. How can I have that code in form of a function or sub so that i can reuse the code by simply passing the stored procedure name to the code. Below is sample of what I am using.



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.txtProcessDate.Text = "" Then
MsgBox("Please Enter The processing Date Before You Continue ", vbOKOnly, "SMIS")
Me.txtProcessDate.Focus()

Else
Try
conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "computationsdelete"
cmd.CommandTimeout = 6000
cmd.ExecuteNonQuery()
cmd.Dispose()
conn.Close()


conn.Open()
cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "deductionssmoothing"
cmd.CommandTimeout = 6000
cmd.ExecuteNonQuery()
cmd.Dispose()
conn.Close()


MsgBox("RECORDS POSTED SUCCESSFULLY. YOU CAN NOW PRINT PAYSLIPS")

conn.Open()
sqlcmd.Parameters.AddWithValue("@d", processdate)
sqlcmd.Connection = conn
sqlcmd.CommandType = CommandType.StoredProcedure
sqlcmd.CommandText = "insertpaymentsanddeductions"
sqlcmd.CommandTimeout = 6000
sqlcmd.ExecuteNonQuery()
sqlcmd.Dispose()

conn.Close()
 
Public Sub CallStoredProcedure(ByVal procedureName as String)
...

cmd.CommandText = procedureName

...
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top