Storing Data

Posted on 2006-04-03
Last Modified: 2010-04-23
So I am new to VB.Net...learned VB from VBA for Excel.  I have a big book of how to's but I am hoping I can get a simple answer.  

Is the only way to create large lists of information (i.e database or spreadsheet) creating an sql database?  I want my list to be stored within the program itself...a stand alone file not tied to any server database.  So how do I store my information to pull from like in Excel or Access?  Is there not a grid tool  Sorry for the simple question...starting from scratch here.  Thanks to everyone in advance for your patience.

Question by:troyhalsey
    LVL 9

    Expert Comment

    Excel file itself can be a database to store information.
    VB.Net is capable to open an excel file, read information and then show it to the user.
    someone has posted a question on how to read and open excel file, .e.g

    if you want to access, it will be better.
    but you will need to migrate all of your data from excel to access

    Author Comment

    What if I don't want to reference another program? Is there no way to store data within the application itself?  My concern is this application I am creating will be used on and off of a network.  So I don't want to have the application tied to any other outside source.  
    LVL 6

    Expert Comment

    You should investigate Serialisation (serialization).

    You can create a class for your data and use serialisation to save it to a file as binary or XML.  Have a look at this little example ... it is a class that can save/load all its property values in a binary data file.

    Imports System.Runtime.Serialization.Formatters.Binary

    <Serializable()> Public Class DataStorage

        Public DataItem as Integer
        Public DataItem2 as String
        Public DataItem3(5) as Boolean

        Public Sub Load(ByVal filepathname as string, ByRef ds as DataStorage)
            Dim formatter As New BinaryFormatter
            Dim fs As FileStream
                fs = New FileStream(filepathname, FileMode.Open)
                ds = CType(formatter.Deserialize(fs), DataStorage)
            Catch ex As Exception
                MsgBox("Unable to load from file [" & filepathname & "]" & vbcrlf & ex.message)
            End Try
        End Sub

        Public Sub Save(ByVal filepathname as string)
            Dim formatter as New BinaryFormatter
            Dim fs as FileStream
                fs = New FileStream(filepathname, FileMode.Create)
                formatter.Serialize(fs, Me)
            Catch ex as Exception
                MsgBox("Unable to save to file [" & filepathname & "]" & vbcrlf & ex.message)
            End Try
        End Function
    End Class

    To use something like this .....

    Dim ds as New DataStorage
    ds.DataItem = 42
    ds.DataItem2 = "Hello World
    ds.DataItem3(2) = True
    ds.DataItem3(4) = True
    ds = nothing

    Dim msg as string
    Dim i as integer
    ds = new DataStorage
    msg = ds.DataItem & vbcrlf & ds.DataItem2 & vbcrlf
    For i=1 to 5
        msg += DataItem3(i) + " "
    LVL 9

    Accepted Solution

    A well structured way to save and retrieve data is using a DataSet and store and retrieve it in a local XML file.
    You can store it in your application directory, in any My Documents directory or in mostly any place you like on your computer.

    Author Comment


    So if I use a DataSet...when I package the application.  It would all go with the loose ends?


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now