[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

VB.Net and stored Procedures

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
AlexPonnath
Asked:
AlexPonnath
  • 2
1 Solution
 
flavoCommented:
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
 
Timbo87Commented:
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
 
flavoCommented:
>> numCols = ds.tables("myTable").columns.count

Damn i'm an idiot
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now