Adding a record to an existing Dataset

I

id10t error

Hello,

I am working on a project where I read in data from a flat file using
a dataset .The program than lets the user scan the barcode. The
problem is when the person scans a barcode on another form and the bar
code is not in the dataset I want to add the new barcode to the
dataset. Here is the code I for the orgianal dataset. Can anyone help
me with this?

Private Sub Load_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim str As String
Dim oRead As System.IO.StreamReader
Dim row As Integer = 0
oRead = File.OpenText("C:\GUNINV\GUNINV.txt")
dt = New DataTable("Gun Inventory")
dt.Columns.Add("gistor", GetType(String))
dt.Columns.Add("gidate400", GetType(String))
dt.Columns.Add("gipage", GetType(String))
dt.Columns.Add("giline", GetType(String))
dt.Columns.Add("gicntl", GetType(String))
dt.Columns.Add("giserl", GetType(String))
dt.Columns.Add("gisku", GetType(String))
dt.Columns.Add("gidesc", GetType(String))
dt.Columns.Add("givend", GetType(String))
dt.Columns.Add("gimanf", GetType(String))
dt.Columns.Add("giloc", GetType(String))
dt.Columns.Add("gidate", GetType(String))
dt.Columns.Add("gitime", GetType(String))
dt.Columns.Add("giuser", GetType(String))
dt.Columns.Add("gistat", GetType(String))
While oRead.Peek <> -1
str = oRead.ReadLine()

dr = dt.NewRow()

dr!gistor = str.Substring(0, 3)
dr!gidate400 = str.Substring(3, 6)
dr!gipage = str.Substring(9, 5)
dr!giline = str.Substring(14, 2)
dr!gicntl = str.Substring(16, 10)
dr!giserl = str.Substring(26, 15)
dr!gisku = str.Substring(41, 10)
dr!Gidesc = str.Substring(51, 25)
dr!Givend = str.Substring(76, 25)
dr!Gimanf = Mid(str, 102, 25)
dr!giloc = ""
dr!gidate = ""
dr!gitime = ""
dr!giuser = ""
dr!gistat = "M"
dt.Rows.Add(dr)

End While
ds.Tables.Add(dt)
 
G

Guest

Not sure I really understand the question, but I will try. You already have
code to load a datarow and add it to the table, so all you need to do when
you want to add a row at some time later is to get a reference to the table
from the dataset...

dim dt as DataTable = ds.Tables("Gun Inventory")
dim dr as DataRow = dt.NewRow()
etc etc etc
 
I

id10t error

Terry,

Thank you so much. That was exactly what I needed. I have the code
working now. This is the code that worked for people who want to know.


dim dt as DataTable = ds.Tables("Gun Inventory")
dim dr as DataRow = dt.NewRow()
dr!gistor = "000"
dt.Rows.Add(dr)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top