Solved

Executing stored procedure with vb.net 2.0

Posted on 2008-06-16
9
348 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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, f…

867 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

20 Experts available now in Live!

Get 1:1 Help Now