Adding more than 1 row to dataset
Hi Guys
Added 1 rec to Access 2000 db from vb.net (1.1), now want to add more than 1... have I done this right?
Unsure of syntax/ order
cheers George
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & myDBLoc)
Dim cmd = New OleDbCommandBuilder(da)
da = New OleDbDataAdapter("Select * from tblDocs", cn)
da.Fill(dt)
cmd = New OleDbCommandBuilder(da)
Try
da.Fill(ds, "Scans")
dt = ds.Tables("Scans")
Dim dr As DataRow = dt.NewRow()
Dim di As New System.IO.DirectoryInfo(myFileNetDrive)
For Each fi As System.IO.FileInfo In di.GetFiles("*.*")
'lstFiles.Items.Add(fi.Name)
dr(1) = myKeyNo.Text
dr(2) = fi.Name
dr(3) = "9"
dr(4) = Date.Now
dt.Rows.Add(dr)
Next
da.Update(ds, "Scans")
Re: Adding more than 1 row to dataset
Without looking at your code in detail the basics seem to be there. I would suggest you try rnning it and see if you get any errors!
Is there a specific point on which you are unsure?
Re: Adding more than 1 row to dataset
first row is added then, then at 2nd dt.Rows.Add(dr) it cracks up
Re: Adding more than 1 row to dataset
oh ic.
inside your for loop you need to create a new instance of your datarow. What your code does currently is try to add teh same datarow (with potentially different values) twice.
Thus inside your for loop add the line
dr = dt.newrow
Re: Adding more than 1 row to dataset
Thanks Duck that worked a treat...now have multiple new records in my wee database
cheers George