I'm not a big database guy, but I did use ms access databases in VB6 to store small amounts of data. Is it just me, or is it more complicated to work with simple databases in .NET? I have been going through the .NET books, and I can't find anything on *simple* databases. I seem to find all these powerful database tools, that I don't require in the apps that I do.
A question for the .NET database familiar folks-
What is the simplest way to have access to small amounts of stored data? Should I use a dataset that gets it data from an XML file?
I write mostly GUI apps that use the com port for modem communciation, and I just need an easy way to store data that the user inputs, i.e., modem phone numbers, site location names, and modem initialization strings.
Any help would be appreciated, or a link in the right direction. I have Googled and Googled, but still come up with database examples that are too rich for what I am doing.
thx -Jared.
Last edited by Jared; Dec 29th, 2002 at 02:46 PM.
"It is preoccupation with possessions, more than anything else, that prevents us from living freely and nobly." -Bertrand Russell
Yes for a simple database its easiest to just load data from an xml file into a dataset. Which is way easier in .NET than VB6.
Once you have your data in a well structured xml file just use the ReadXML method of the dataset to covert it to data and the WriteXML to convert it back.
If you want to use a strongly typed dataset then make the xml file, then right click in it and hit 'create schema' then go to view the schema right click again and hit 'generate dataset'.
Okay here it is. You will need to place the XML file (I uploaded it as .txt file) into the C: drive, a form with three buttons, a combobox and a datagrid
VB Code:
Dim ds As New DataSet()
'This loads the xml file into the dataset/grid.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Clears any previous info, before loading the new, revised data.
ds.Clear()
ds.ReadXml("C:\directory.xml") 'location of xml file
DataGrid1.SetDataBinding(ds, "site") 'bind it.
End Sub
'This will take the changed data in the grid and write it to xml file.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
DataGrid1.SetDataBinding(ds, "site")
ds.WriteXml("C:\directory.xml")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'Clear the list box, otherwise you will have redundant entries.
ComboBox1.Items.Clear()
'This gets the data from the Grid, and puts them in the Combobox. This needs improvement, any suggestions? I am using the exception to stop the counting.
Dim x As Integer = 0
Try
Do Until x = -1
ComboBox1.Items.Add(DataGrid1.Item(x, 0))
x += 1
Loop
Catch ex As Exception
If Err.Number = 9 Then
Exit Sub
Else
MsgBox(Err.Number & " " & Err.Description)
End If
End Try
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
'This shows the data selected and the info in row 'z', column 1.
I had to use an exception stop the counting on my loop. Is there anyway to find the number of rows in a dataset or grid? I tried the datagrid1.visiblerowcount, but it did not return correct values when performed consecutively.
-Thx
"It is preoccupation with possessions, more than anything else, that prevents us from living freely and nobly." -Bertrand Russell
I have data in my grid, not sure why I'm getting this msg.
An unhandled exception of type 'System.NullReferenceException' occurred in pcms.exe
Additional information: Object reference not set to an instance of an object.
VB Code:
Dim cmdView As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("select item_no, activity, account_no from pcms.pcms_item_activity where item_no='" & txtItem.Text & "' and activity='" & txtActivity.Text & "'", objCon)