Callum K

Hi there!

I downloaded Visual Basic Express 2008 (beta 2), and I was wondering if I could have some help with a program I am hoping to develop for myself. I was looking for code that will allow me to save the contents of a 'Datagrid' to a seperate file, and then I would like to re-open that file and display the saved information in the same 'Datagrid'. I tried some code I knew from VB 6. but it never worked.

All help will be greatly appreciated!

Thanks!

Callum K (16)




Re: Visual Basic 2008 (Pre-release) Save and re-open a file? Can you help?

Beth Massi - MSFT

Hi Callum,

If your DataGrid is displaying data in a DataSet then you can easily save the Dataset data to disk and reload it later. Assuming you have a DataSet on your form using drag-drop databinding (like shown in this video) you can do something similar to the following:

Code Block

'Flush the data in the grid into the DataSet

Me.Validate()

Me.MyBindingSource.EndEdit()

'Write the data to disk

Me.MyDataSet.WriteXml("C:\myfile.xml", XmlWriteMode.WriteSchema)

'Later you can read the data back into the dataset from disk

Me.MyDataSet.ReadXml("C:\myfile.xml")

HTH,

-B

Beth Massi, VS Community

Visit the Visual Basic Developer Center