4 Replies - 1032 Views - Last Post: 27 January 2012 - 12:52 PM Rate Topic: -----

#1 DFWOscar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 26-January 12

Run a SQL Stored Procedure from VB.Net

Posted 26 January 2012 - 07:56 AM

Hello,

i am currently building an ASPX webpage for internal use. Basically, there are two buttons on this page and I need each one to kick off a different stored procedure on our local SQLServer based on the needed task.
these stored rocedures do quite a bit of work and take 3-5 minutes to finish running. In neither case do I need any kind of gridview or other output from these stored procedures, as they are simply crunching/cleaning data that will populate some tables that the user will then use to complete their task. There are also no inputs or parameters needed.

So i'm OK at ASPX and pretty good at SQL, but have no idea on the VB code behind page. This is what I have ben able to put together based on 3 days of googling. i think i am close but can't quite get across the line.


Imports System.Data.SqlClient

Partial Class _Default
    Inherits System.Web.UI.Page


    Protected Sub RunBillingButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RunBillingButton.Click
        RunBillingButton.Attributes.Add("onclick", "return confirm('Did you remember to check the Box?');")
        Dim con As String = ConfigurationManager.ConnectionStrings("KFileAddString").ConnectionString
        Dim cmd As New SqlCommand("sp_Production")
        cmd.CommandType = Data.CommandType.StoredProcedure

        con.Open()
        If CheckBox1.Checked = True Then
            cmd.CommandText = "sp_Production"
        End If

    End Sub

End Class 


I'm not sure if you need to see any of my ASPX or my SQL. both work fine on their own, but i am not able to get these buttons to work.

Thanks

Oscar Stiles

Is This A Good Question/Topic? 0
  • +

Replies To: Run a SQL Stored Procedure from VB.Net

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,926
  • Joined: 25-September 09

Re: Run a SQL Stored Procedure from VB.Net

Posted 26 January 2012 - 11:56 AM

Where are you executing the command (cmd)?
Was This Post Helpful? 0
  • +
  • -

#3 DFWOscar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 26-January 12

Re: Run a SQL Stored Procedure from VB.Net

Posted 26 January 2012 - 01:51 PM

I am not sure to be honest. i am not at all familiar with VB.Net syntax.
I have tried to read through some tutorials but it still escapes me. It seems very different than SQL or ASPX or pascal, which are all languages I have experience with. So I really do not know any of the commands or what Dim is/means.
Again, i have tried to do my homework on this, as it were, but i am not sure how to finish the job.
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,926
  • Joined: 25-September 09

Re: Run a SQL Stored Procedure from VB.Net

Posted 26 January 2012 - 04:38 PM

Well, I haven't studied your code but assuming, you've set up your connection properly, let's look at this block
  If CheckBox1.Checked = True Then
     cmd.CommandText = "sp_Production"
  End If


This could also simply have the statement in it
  If CheckBox1.Checked = True Then
     cmd.CommandText = "INSERT INTO myTable (colA, colB) VALUES ("Charlie", "May")
     'But... This is only defining the statement to the command. Now you need to execute it
     cmd.ExecuteNonQuery ' This execute a Non-Query (Not a SELECT statement) 
  End If


This tutorial might help
Was This Post Helpful? 0
  • +
  • -

#5 Shadar  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 157
  • Joined: 26-May 09

Re: Run a SQL Stored Procedure from VB.Net

Posted 27 January 2012 - 12:52 PM

You might try looking at this. Even if you don't use it, it is pretty good for a learning tool.

SQL Module

This post has been edited by Shadar: 27 January 2012 - 12:53 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1