Results 1 to 5 of 5

Thread: Adding more than 1 row to dataset

  1. #1

    Thread Starter
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Resolved 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")

    Last edited by Ggalla1779; Feb 6th, 2006 at 11:32 AM.

  2. #2
    Hyperactive Member The_Duck's Avatar
    Join Date
    May 2005
    Location
    Leamington, UK
    Posts
    351

    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?

  3. #3

    Thread Starter
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    Re: Adding more than 1 row to dataset

    first row is added then, then at 2nd dt.Rows.Add(dr) it cracks up

  4. #4
    Hyperactive Member The_Duck's Avatar
    Join Date
    May 2005
    Location
    Leamington, UK
    Posts
    351

    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

  5. #5

    Thread Starter
    Fanatic Member Ggalla1779's Avatar
    Join Date
    Feb 2006
    Location
    Glasgow
    Posts
    532

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width