|
-
Dec 2nd, 2003, 11:01 AM
#1
Thread Starter
Hyperactive Member
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:
Private Sub RefillDataGrid()
Dim cnn As New OleDb.OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strDataBaseName)
Dim cmd As New OleDb.OleDbCommand
cnn.Open()
cmd.Connection = cnn
Dim da As New OleDb.OleDbDataAdapter
Dim DsPayroll1 As New DataSet
Try
cmd = cnn.CreateCommand
cmd.CommandText = "Select * From TimeGR"
'***********************************************
'"Select * From TimeGR Where EmployeeNumber='" & _
'(txtEmp.Text) & "'"
'***********************************************
da.SelectCommand = cmd
da.Fill(DsPayroll1, "TimeGR")
DataGrid1.DataSource = DsPayroll1
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, _
MsgBoxStyle.OKCancel, "Populate Datagrid")
End Try
cnn.Close()
Thanks
-
Dec 2nd, 2003, 03:31 PM
#2
Frenzied Member
You have to bind directly to the datatable. Try this
VB Code:
da.Fill(DsPayroll1, "TimeGR")
DataGrid1.DataSource = DsPayroll1.Tables("TimeGR")
-
Dec 2nd, 2003, 03:59 PM
#3
Thread Starter
Hyperactive Member
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.
-
Dec 2nd, 2003, 05:28 PM
#4
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|