Results 1 to 7 of 7

Thread: Simple Database in VB.NET vs VB6 [Resolved]

  1. #1

    Thread Starter
    Member Jared's Avatar
    Join Date
    Nov 2002
    Posts
    58

    Simple Database in VB.NET vs VB6 [Resolved]

    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

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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'.

  3. #3

    Thread Starter
    Member Jared's Avatar
    Join Date
    Nov 2002
    Posts
    58
    Thanks for your reply...

    I am not at my IDE station right now, so I can't play with it now, but I will give it a shot and reply later, thanks.

    That was the simple answer that I was looking for
    "It is preoccupation with possessions, more than anything else, that prevents us from living freely and nobly." -Bertrand Russell

  4. #4

    Thread Starter
    Member Jared's Avatar
    Join Date
    Nov 2002
    Posts
    58
    It worked, let me clean up the code, then I'll post it.
    Last edited by Jared; Dec 28th, 2002 at 11:18 AM.
    "It is preoccupation with possessions, more than anything else, that prevents us from living freely and nobly." -Bertrand Russell

  5. #5

    Thread Starter
    Member Jared's Avatar
    Join Date
    Nov 2002
    Posts
    58
    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:
    1. Dim ds As New DataSet()
    2.  
    3.     'This loads the xml file into the dataset/grid.
    4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5.         'Clears any previous info, before loading the new, revised data.
    6.         ds.Clear()
    7.         ds.ReadXml("C:\directory.xml") 'location of xml file
    8.         DataGrid1.SetDataBinding(ds, "site") 'bind it.
    9.     End Sub
    10.  
    11.     'This will take the changed data in the grid and write it to xml file.
    12.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    13.         DataGrid1.SetDataBinding(ds, "site")
    14.         ds.WriteXml("C:\directory.xml")
    15.     End Sub
    16.  
    17.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    18.         'Clear the list box, otherwise you will have redundant entries.
    19.         ComboBox1.Items.Clear()
    20.         '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.
    21.         Dim x As Integer = 0
    22.         Try
    23.             Do Until x = -1
    24.                 ComboBox1.Items.Add(DataGrid1.Item(x, 0))
    25.                 x += 1
    26.             Loop
    27.         Catch ex As Exception
    28.             If Err.Number = 9 Then
    29.                 Exit Sub
    30.             Else
    31.                 MsgBox(Err.Number & " " & Err.Description)
    32.             End If
    33.         End Try
    34.     End Sub
    35.  
    36.     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    37.         'This shows the data selected and the info in row 'z', column 1.
    38.         Dim z As String
    39.         z = ComboBox1.SelectedIndex
    40.         MsgBox(ComboBox1.SelectedText & DataGrid1.Item(z, 1))
    41.  
    42.     End Sub

    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
    Attached Files Attached Files
    "It is preoccupation with possessions, more than anything else, that prevents us from living freely and nobly." -Bertrand Russell

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    VB Code:
    1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    2.         'Clear the list box, otherwise you will have redundant entries.
    3.         ComboBox1.Items.Clear()
    4.         'you can get the data from the dataset either by adding them one by one
    5.         Dim dr As DataRow
    6.         For Each dr in ds.Tables("site").Rows
    7.                 ComboBox1.Items.Add(ds(0).ToString)
    8.         Next
    9.  
    10.         'or you can add them all at once
    11.         ComboBox1.Items.AddRange(ds.Tables("site").Rows)
    12.         ComboBox1.DisplayMember="NameOfFieldToShow"
    13.  
    14.         'or just use databinding
    15.         ComboBox1.DataSource=ds.Tables("site")
    16.         ComboBox1.DisplayMember="NameOfFieldToShow"
    17.  
    18.     End Sub

  7. #7
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    loop through grid

    I'm getting an error msg on this line:

    For Each dr In ds.Tables("cards").Rows

    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:
    1. 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)
    2.         ds = New DataSet()
    3.         cmdView.Fill(ds, "cards")
    4.         DataGrid1.DataSource = ds
    5.         DataGrid1.DataMember = "cards"
    6.         objCon.Close()
    7.  
    8.  Dim dr As DataRow
    9.         For Each dr In ds.Tables("cards").Rows
    10.             MsgBox("Whatever")
    11.         Next
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width