This is a two part question,
1) The code below should display a form with a datagridview and a few
command buttons. This form should allow the user to make change to the
records displayed
in the datagridview and have to changes written to the Filters table in
an MS Access database. The if the user chooses, clicking on the Restore
button empties
the contents of the Filters table, refills it with the contents of the
DefaulFilters Table, and refreshes the contents of the Datagridview to
reflect that the defaults
have been reloaded. All of this works except the part where the
datagridview gets refreshed. I can close the form and reopen it and the
default data is loaded,
but it is not loaded without closing and reopening the form. How can I
refresh the datagrid view without closing and opening the form?
2) This one may be a bit harder. The code in the Restore sub below was
built by coping, pasting, and modifing examples in the newsgroups as is most
of my code.
If someone has time, could you please write a few lines that explain
what each of the line of code are doing. I follow that a connection to
the database is open,
two DataAdapters are open for each of the two database tables, these
DataAdapters are used to fill two DataSets, and then I get lost.
Thanks for any help with either of the above.
Thomas
Private Sub frmFilters_Load (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load, MyBase.Load
Me.FiltersTable Adapter.Fill(Me .TAMDataSet.Fil ters)
End Sub
Private Sub cmdRestore_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdRestore.Clic k
'This sub empties the Filters Table. Copies the records in the
DefaultFilters table
'and places them them in the Filters Table. Then it refreshes the
datagridviewer with the
'new records.
Dim myConnection As New OleDbConnection (strConn)
Dim ds As DataSet = New DataSet
Dim ds2 As DataSet = New DataSet
Dim tblDefaultFilte rs As DataTable
Dim tblCopyDefaultF ilters As DataTable
'Delete all records in the FILTERS Table
strSQL = "DELETE * FROM FILTERS"
cmd = New OleDb.OleDbComm and(strSQL, cn)
rdr = cmd.ExecuteRead er
myConnection.Op en()
Dim da As OleDb.OleDbData Adapter = New
OleDb.OleDbData Adapter("Select * from DefaultFilters" , myConnection)
Dim da2 As OleDb.OleDbData Adapter = New
OleDb.OleDbData Adapter("Select * from Filters", myConnection)
da.Fill(ds)
da2.Fill(ds2)
tblDefaultFilte rs = ds.Tables(0)
Dim CB As OleDb.OleDbComm andBuilder = New
OleDb.OleDbComm andBuilder(da2)
tblCopyDefaultF ilters = tblDefaultFilte rs.Copy()
tblCopyDefaultF ilters = CType(tblDefaul tFilters.Clone( ), DataTable)
For Each row As DataRow In tblDefaultFilte rs.Rows
Dim newRow As DataRow = tblCopyDefaultF ilters.NewRow()
For Each col As DataColumn In tblDefaultFilte rs.Columns
newRow(col.Colu mnName) = row(col.ColumnN ame)
Next col
tblCopyDefaultF ilters.Rows.Add (newRow)
Next row
da2.Update(tblC opyDefaultFilte rs)
'Clear and refill the dataset and data adapter
'then refresh the datagrid
Me.TAMDataSet.C lear()
Me.FiltersTable Adapter.Fill(Me .TAMDataSet.Fil ters)
Me.DataGridView 1.Refresh()
myConnection.Cl ose()
End Sub
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
1) The code below should display a form with a datagridview and a few
command buttons. This form should allow the user to make change to the
records displayed
in the datagridview and have to changes written to the Filters table in
an MS Access database. The if the user chooses, clicking on the Restore
button empties
the contents of the Filters table, refills it with the contents of the
DefaulFilters Table, and refreshes the contents of the Datagridview to
reflect that the defaults
have been reloaded. All of this works except the part where the
datagridview gets refreshed. I can close the form and reopen it and the
default data is loaded,
but it is not loaded without closing and reopening the form. How can I
refresh the datagrid view without closing and opening the form?
2) This one may be a bit harder. The code in the Restore sub below was
built by coping, pasting, and modifing examples in the newsgroups as is most
of my code.
If someone has time, could you please write a few lines that explain
what each of the line of code are doing. I follow that a connection to
the database is open,
two DataAdapters are open for each of the two database tables, these
DataAdapters are used to fill two DataSets, and then I get lost.
Thanks for any help with either of the above.
Thomas
Private Sub frmFilters_Load (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load, MyBase.Load
Me.FiltersTable Adapter.Fill(Me .TAMDataSet.Fil ters)
End Sub
Private Sub cmdRestore_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdRestore.Clic k
'This sub empties the Filters Table. Copies the records in the
DefaultFilters table
'and places them them in the Filters Table. Then it refreshes the
datagridviewer with the
'new records.
Dim myConnection As New OleDbConnection (strConn)
Dim ds As DataSet = New DataSet
Dim ds2 As DataSet = New DataSet
Dim tblDefaultFilte rs As DataTable
Dim tblCopyDefaultF ilters As DataTable
'Delete all records in the FILTERS Table
strSQL = "DELETE * FROM FILTERS"
cmd = New OleDb.OleDbComm and(strSQL, cn)
rdr = cmd.ExecuteRead er
myConnection.Op en()
Dim da As OleDb.OleDbData Adapter = New
OleDb.OleDbData Adapter("Select * from DefaultFilters" , myConnection)
Dim da2 As OleDb.OleDbData Adapter = New
OleDb.OleDbData Adapter("Select * from Filters", myConnection)
da.Fill(ds)
da2.Fill(ds2)
tblDefaultFilte rs = ds.Tables(0)
Dim CB As OleDb.OleDbComm andBuilder = New
OleDb.OleDbComm andBuilder(da2)
tblCopyDefaultF ilters = tblDefaultFilte rs.Copy()
tblCopyDefaultF ilters = CType(tblDefaul tFilters.Clone( ), DataTable)
For Each row As DataRow In tblDefaultFilte rs.Rows
Dim newRow As DataRow = tblCopyDefaultF ilters.NewRow()
For Each col As DataColumn In tblDefaultFilte rs.Columns
newRow(col.Colu mnName) = row(col.ColumnN ame)
Next col
tblCopyDefaultF ilters.Rows.Add (newRow)
Next row
da2.Update(tblC opyDefaultFilte rs)
'Clear and refill the dataset and data adapter
'then refresh the datagrid
Me.TAMDataSet.C lear()
Me.FiltersTable Adapter.Fill(Me .TAMDataSet.Fil ters)
Me.DataGridView 1.Refresh()
myConnection.Cl ose()
End Sub
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access