Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

Storing Data

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)....by 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 VB.net?  Sorry for the simple question...starting from scratch here.  Thanks to everyone in advance for your patience.

Troy
0
troyhalsey
Asked:
troyhalsey
1 Solution
 
marchianoCommented:
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
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_20972338.html

if you want to access, it will be better.
but you will need to migrate all of your data from excel to access
0
 
troyhalseyAuthor Commented:
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.  
0
 
DeadlyTrevCommented:
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
Imports System.io

<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
        Try
            fs = New FileStream(filepathname, FileMode.Open)
            ds = CType(formatter.Deserialize(fs), DataStorage)
            fs.Close()
        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
        Try
            fs = New FileStream(filepathname, FileMode.Create)
            formatter.Serialize(fs, Me)
            fs.Close()
        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.Save("C:\DataStorage.dat")
ds = nothing

Dim msg as string
Dim i as integer
ds = new DataStorage
ds.Load(ds)
msg = ds.DataItem & vbcrlf & ds.DataItem2 & vbcrlf
For i=1 to 5
    msg += DataItem3(i) + " "
Next
MsgBox(msg)
0
 
jrschererCommented:
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.

http://www.codeguru.com/vb/gen/vb_database/adonet/article.php/c5153/

Jack.net
0
 
troyhalseyAuthor Commented:
Jack-

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

Troy
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now