0

I am unable to save the contents of my DataTable "dtable" The scope of this Setting is USER, however although it saves it while the program is running. When I launch the program and re-load My.Settings.Sales_Mapping it is empty.

Can anyone help ?

    My.Settings.Sales_Mapping = dtable
            My.Settings.Save()
Rob4236
  • 375
  • 1
  • 7
  • 12
  • likely because My.Settings does not have a DataTable type. A DataTable is an object, so it cannot be serialized (which is what Settings does), since it has no idea of what is in the DT it fails. If it is in a DT where did the data come from? – Ňɏssa Pøngjǣrdenlarp Mar 04 '15 at 22:21
  • Hi There, It is set as a DataTable and it is coming from a DataGridView Dim dtable As DataTable = CType(Me.SettingsDataGridView.DataSource, DataTable) – Rob4236 Mar 04 '15 at 22:25
  • If it helps when I debug and close the Form, it jumps to Settings.Designer piece of code below: ` #If _MyType = "WindowsForms" Then If Not addedHandler Then SyncLock addedHandlerLockObject If Not addedHandler Then AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings addedHandler = True End If End SyncLock End If #End If ` – Rob4236 Mar 04 '15 at 22:30
  • A DataTable is an object. an object cannot be serialized, just the information inside. Settings has no idea what is inside. *where did the data in the DT come from?* – Ňɏssa Pøngjǣrdenlarp Mar 04 '15 at 22:42
  • I Created it like this ... ' Dim dt As New DataTable dt.Columns.Add("Site Code") dt.Columns.Add("Group Code") dt.Columns.Add("Nominal") dt.Rows.Add(1, 1, 1) My.Settings.Sales_Mapping = dt' – Rob4236 Mar 04 '15 at 22:44
  • you could always use the `WriteXML` and `ReadXML` methods to save/load the data yourself. – Ňɏssa Pøngjǣrdenlarp Mar 04 '15 at 22:52
  • can you use that and load into datagridview ? – Rob4236 Mar 04 '15 at 23:35
  • of course. the DGV binds to the data in the DT. it has no idea where the data came from or how it was saved or loaded – Ňɏssa Pøngjǣrdenlarp Mar 04 '15 at 23:54

0 Answers0