Results 1 to 4 of 4

Thread: Problem with (new) datagrid / dataset

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354

    Problem with (new) datagrid / dataset

    I have a dataset in a Datagrid that is not working the way that is should. At one time it was fine but somehow I messed it up

    When I first load the dataset this is what I get



    Then (Once Clicked)



    And finally (After Second Click)



    It used to open up with the full grid loaded the first time. Here is the code I am using. Any ideas what went wrong and how to fix it?
    VB Code:
    1. Private Sub RefillDataGrid()
    2.  
    3.         Dim cnn As New OleDb.OleDbConnection( _
    4.                "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    5.                "Data Source=" & strDataBaseName)
    6.         Dim cmd As New OleDb.OleDbCommand
    7.         cnn.Open()
    8.         cmd.Connection = cnn
    9.  
    10.         Dim da As New OleDb.OleDbDataAdapter
    11.         Dim DsPayroll1 As New DataSet
    12.         Try
    13.             cmd = cnn.CreateCommand
    14.  
    15.             cmd.CommandText = "Select * From TimeGR"
    16.  
    17.             '***********************************************
    18.             '"Select * From TimeGR Where EmployeeNumber='" & _
    19.             '(txtEmp.Text) & "'"
    20.             '***********************************************
    21.  
    22.             da.SelectCommand = cmd
    23.             da.Fill(DsPayroll1, "TimeGR")
    24.             DataGrid1.DataSource = DsPayroll1
    25.         Catch ex As Exception
    26.             MsgBox("Error: " & ex.Source & ": " & ex.Message, _
    27.             MsgBoxStyle.OKCancel, "Populate Datagrid")
    28.         End Try
    29.         cnn.Close()

    Thanks

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You have to bind directly to the datatable. Try this
    VB Code:
    1. da.Fill(DsPayroll1, "TimeGR")
    2. DataGrid1.DataSource = DsPayroll1.Tables("TimeGR")

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Location
    Three Rivers, MI
    Posts
    354
    That did the trick. Thank you. By the way what is the proper way to clear the datagrid so that I can refresh the content (reload dataset) for the user?

    Basicaly I need to refresh the content in the datagrid as the user adds and or deletes records from text boxes in the grid.

    I know how to do the add and delete but I am not sure how to get the results back to user.

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Just re-bind the dataset.

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