Link to home
Create AccountLog in
Avatar of ty-exexch-ko
ty-exexch-koFlag for Albania

asked on

Using records to store a set of data (Vb.NET)

How I can identify records as a variable to store a set of data ?

That meaning I do not need a database to store that data.
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

What exactly do you want to do ?
You can create a class, and create a generic list of it to store the data in memory

See example below with a person-class
http://www.vbdotnetheaven.com/UploadFile/Saurabh.Mishra/GenericsInCsharp211232006000706AM/GenericsInCsharp2.aspx
Avatar of ty-exexch-ko

ASKER

Not C# I need in VB.NET
load your data into a dataset
use dataset.writexml to save the data to a file
then in your application you can create a new dataset and use the dataset.ReadXml method to access the data. After editing it you can write it back to disk.
Strange, the article is written in vb.net and indeed the first example is in c#

Example of student-class
http://www.java2s.com/Code/VB/Generics/UseGenericListtostoreyourownObject.htm

Customers-example
http://www.java2s.com/Code/VB/Generics/GenericListstoresGenericClass.htm
I don't want to store it with any types of files

I think there a recordset variable you can temprary stored variables
Avatar of klakkas
klakkas

Hello. As Dhaest says, you can use a class to store your data.
If you want to emulate a Database, you could create a dataTable in runtime.

Assuming you have a list of Students you want to store.

Example with Class (Recomended).

Public class Student
   Public FirstName as string
   Public LastName as string
   Public FathersName as string
   Public Class as string
   Public GradePointAverage as double
End Class

And in your code, you say:
dim AllStudents as new list (of Student)
dim s as new Student
s.FirstName = "Kyriakos"
'... Fill the remaining fields
AllStudents.Add (s)

Example with Datatable:
Dim dt as new Datatable
dt.Columns.add ("FirstName", getType(string))
dt.Columns.add ("LastName ", getType(string))
dt.Columns.add ("FathersName", getType(string))
dt.Columns.add ("Class", getType(string))
dt.Columns.add ("GradePointAverage", getType(double))

dim r as datarow = dt.newrow
r.item("firstName") = "Kyriakos"
'... Fill the remaining fields
dt.rows.add(r)

Hope this helps.
You can use a DataTable object. Its a table but you dont have to save it anywhere. It saves your data in memory.

Dim dTable As New DataTable
dTable.Columns.Add("EmpID", GetType(Integer))
dTable.Columns.Add("Name", GetType(String))

For I As Integer = 0 to 9
      Dim drow as DataRow = dTable.NewRow()
      drow(0)="ID" & I
      drow(1)="Name" & I
      dTable.Rows.Add(drow)
Next

'Your table contains 10 rows. You can set it as a data source to many controls such as a grid.
What exactly do you want to do ?
Hi CodeCruiser

How I can display the values inside the datatable ?
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account