Solved

Executing stored procedure with vb.net 2.0

Posted on 2008-06-16
9
347 Views
Last Modified: 2013-11-26
Hi,
I am using a richtextbox to load a stored procedure in vb.net application.
Any points regarding how to execute the stored procedur like query analyser with vb.net will be helpful

Regards
0
Comment
Question by:anusdesai
  • 5
  • 4
9 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 21792228
Is your stored procedure on your database ?

The Ins and Outs of Stored Procedures in VB.NET
http://www.vbdotnetheaven.com/UploadFile/dclark/StoredProceduresinVBdotNET04082005072716AM/StoredProceduresinVBdotNET.aspx
0
 

Author Comment

by:anusdesai
ID: 21792422
Cheers ! will try and be right back
0
 

Author Comment

by:anusdesai
ID: 21793300
Hi,
There is no specific method given in the article...
any example of function or procedure will be helpful

Cheers
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 21793320
Do you have a stored procedure on your sql-server ?
Calling Stored Procedures with ADO.NET
http://www.developer.com/db/article.php/3438221


Below you can find an example to call the stored procedure "SelectCustomer" with 1 parameter
Public Sub SelectCustomer()

    Dim connection As SqlConnection = _

        New SqlConnection(connectionString)

    connection.Open()

    Try
 

        Dim command As SqlCommand = _

            New SqlCommand("SelectCustomer", _ connection)

        command.Parameters.Add("@CustomerID", "PAULK")

        command.CommandType = CommandType.StoredProcedure
 

        Dim adapter As SqlDataAdapter = New SqlDataAdapter(command)
 

        Dim table As DataTable = New DataTable

        adapter.Fill(table)
 

    Catch ex As Exception

        Console.WriteLine(ex.Message)

        Throw

    Finally

        connection.Close()

    End Try

End Sub

Open in new window

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:anusdesai
ID: 21794107
Hi,
Cheers
But ,the requirement is i have a script in my sqlbox example
Go
declare @i smallint

set @i = 1

Update abc set @i = no =  
                  case @i
                        when 1 then Countstmode
                        else @i - 1
                  End
GO

 
I need to read the script line by line and then execute .

Cheers
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 21800173
Did you try the following:

Dim sqlComm As New SqlCommand(YourSqlBox.Text, sqlConn)
sqlComm.ExecuteNonQuery
0
 

Author Comment

by:anusdesai
ID: 21801013
Cheers ...will try abd be right back
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 21819800
Did it solve your problem ?
0
 

Author Closing Comment

by:anusdesai
ID: 31467530
Cheers mate..sorry for replying late was away for a while.
Cheers for being so concerned.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now