Solved

VB.Net and stored Procedures

Posted on 2004-10-24
325 Views
Last Modified: 2010-04-23
I have some code which calls a stored procedure

Dim cn As New SqlConnection("Data Source=localhost; Initial Catalog=lergdb; User ID=sa; Password=")
cn.Open()

Dim Sql As String
Sql = "sp_getNpaInfo"

Dim cmd As New SqlCommand(Sql, cn)
cmd.CommandType = CommandType.StoredProcedure

cmd.Parameters.Add("@npa", 949)
cmd.Parameters.Add("@nxx", 489)

Dim dr As SqlDataReader = cmd.ExecuteReader()


i would to like to be able to do the folowing...

a) bind the resault to a controle like a grid or so...
b) read dat data into a table of a dataset
c) able to tell how many rows are in the resault..

0
Question by:AlexPonnath
    3 Comments
     
    LVL 34

    Expert Comment

    by:flavo
    1 and 2

    This is for oleDb, just modify to suit slq

    dim adpt as new oledbAddapter
    dim ds as new dataset
    adpt.SelectCommand = cmd
    ds = New DataSet
    adpt.Fill(ds, "myTable")
    me.myDatagrid.datasource = ds.tables("myTable")
    'dont forget to close and dispose you objects

    3.

    me.myDataGrid.visiblerowscount

    or

    numCols = ds.tables("myTable").columns.count

    Dont have VS .Net on me, so please mind the air code (all done off the top of my head)

    Dave
    0
     
    LVL 15

    Accepted Solution

    by:
    1 and 2:

    Dim da As New SqlDataAdapter(cmd)
    Dim ds As New DataSet
    da.Fill(ds, "TableName")
    dataGrid1.DataSource = ds.Tables("TableName").DefaultView
    dataGrid1.DataBind()

    3.
    ds.Tables("TableName").Rows.Count
    0
     
    LVL 34

    Expert Comment

    by:flavo
    >> numCols = ds.tables("myTable").columns.count

    Damn i'm an idiot
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    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

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    846 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

    7 Experts available now in Live!

    Get 1:1 Help Now