Solved

ret row return

Posted on 2011-09-02
2
376 Views
Last Modified: 2012-05-12
How can I get a return row when I run a store procedure?
Say i have a store procedure name called "Order_select_all". Can I run a seperate select statement to get row count?

like

exec Order_select_all
select rows return etct...

sorry, I am new here.
0
Comment
Question by:VBdotnet2005
2 Comments
 
LVL 6

Assisted Solution

by:c1nmo
c1nmo earned 62 total points
ID: 36476528

For UPDATE,INSERT,DELETE:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery(v=vs.71).aspx

For SELECT something like:

Imports System.Data.SqlClient
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim connetionString As String
        Dim connection As SqlConnection
        Dim command As SqlCommand
        Dim adapter As New SqlDataAdapter
        Dim ds As New DataSet
        Dim sql As String

            connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
            sql = "Your SQL Statement Here"
        connection = New SqlConnection(connetionString)

        Try
            connection.Open()
            command = New SqlCommand(sql, connection)
            adapter.SelectCommand = command
            adapter.Fill(ds, "SQL Temp Table")
            adapter.Dispose()
            command.Dispose()
            connection.Close()

            MsgBox("Number of row(s)  -  " & ds.Tables(0).Rows.Count)

        Catch ex As Exception
            MsgBox("Can not open connection ! ")
        End Try
    End Sub
End Class
 

0
 
LVL 9

Accepted Solution

by:
mimran18 earned 63 total points
ID: 36479493
try this.

Drop TABLE [dbo].[Test]
Go
CREATE TABLE [dbo].[Test](
    [ID] int,
      [Name] [nvarchar](50)
)
GO

Insert into [test] values (1,'test1')
Insert into [test] values (2,'test2')
Insert into [test] values (3,'test3')
GO
Drop Procedure test_sp
Go

Create Procedure test_sp
as
Select * from test
Select @@rowcount
Go
test_sp
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql Audit table 3 84
passing parameter in sql procedure 9 68
display data in text field from data base for updating 6 71
Need help in debugging a UDF results 7 53
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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