Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding a datalist with paging to Stored Procedure

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
I am using the following code to bind a datalist to a query from an SQL database:

Code:
Dim Query As String = "select * from Customers"
        objcn = New SqlConnection(ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString)
        objAd = New SqlDataAdapter(Query, objcn)
        objDs = New DataSet
        If Not IsPostBack Then
            objAd.Fill(objDs)
            lblRecordCount.Text = objDs.Tables(0).Rows.Count.ToString
           
        End If
        objAd.Fill(objDs, Convert.ToInt32(lblCurrentIndex.Text), Convert.ToInt32(lblPagesize.Text), "tblEmp")
        dlCustomers.DataSource = objDs.Tables("tblEmp").DefaultView
        dlCustomers.DataBind()

How do I implement the following code to I replace the Query string with this code:
Code:
Dim strConnString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
        Dim con As New SqlConnection(strConnString)
        Dim cmd As New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "spGetCustomers"
        cmd.Connection = con

I know its probably pretty simple, but I have tried plenty of solutions but can get none of them to bind correctly.

Thanks
 
Why are you changing the way you are getting your data?
This should help you understand what you are trying to do can't be done with your new code.
 
like that

Code:
Dim strConnString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
        Dim con As New SqlConnection(strConnString)
        Dim cmd As New SqlCommand()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "spGetCustomers"
        cmd.Connection = con 
        Dim  adapter as new SqlDataAdapter(cmd)
        Dim ds as new DataSet()
        adapter.Fill(ds)
        adapter.Dispose()
        cmd.Dispose()
        dlCustomers.DataSource = ds
        dlCustomers.DataBind()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top