×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

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

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

(OP)
Public Sub CallStoredProcedure(ByVal procedureName as String)
...

cmd.CommandText = procedureName

...
End Sub

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

What does this have to do with Visual InterDev?

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

(OP)
What is your point @delettante?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close