Results 1 to 2 of 2

Thread: Need help with datagrid and dataset in ASP.NET

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    Need help with datagrid and dataset in ASP.NET

    I got it down how to fill a datagrid with a dataset. The difficulty is when I try to rewrite back to the database with the SQLDataAdapter. The page refreshes on the 'Update' button click so the DataSet is empty. How to I slurp the data off of the Datagrid back into the DataSet?

    Here's some of my pseudo-code:

    -------------------------------------
    The fill grid part works:

    Private Sub btnFillGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFillGrid.Click

    Dim sqlcomm As New SqlCommand("SELECT * from WebUsers")
    sqlcomm.Connection = cn

    Dim sqlda As New SqlDataAdapter
    sqlda.SelectCommand = sqlcomm

    cn.Open()
    sqlda.Fill(ds)
    cn.Close()

    dgUsers.DataSource = ds
    dgUsers.DataBind()

    ----------------------------------------------------------------

    Private Sub btnGridUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGridUpdate.Click

    ' The Update command is declared elsewhere and it works
    ' the ds is declared as a dataset class variable

    ' need code to fill modified dataset with changes so this update will work

    Dim sqlda As New SqlDataAdapter
    Dim sqlupd As SQLCommand = SQLUpdateCommand1

    sqlda.UpdateCommand = sqlupd

    sqlupd.Connection = cn

    cn.Open()
    sqlda.Update(ds)
    cn.Close()

    End Sub

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Need help with datagrid and dataset in ASP.NET

    Store the dataset in a viewstate variable.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width