5 Replies - 7966 Views - Last Post: 24 January 2012 - 11:16 AM Rate Topic: -----

#1 vbnet9  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 346
  • Joined: 26-May 09

Adding records to Access database

Posted 15 May 2011 - 02:24 PM

I have been trying for a month to get a row added to an Access database and can not do it. Please help.

I have the databindings all set and can select different records, but can not add a new one.

I have tried BindingSource.AddNew.row() but can't figure out how to add data to the new row, nor does it show in the database.

I have tried

 Dim ds As New myDataSet '<---Change this to the dataset name on your form
        Dim dr As DataRow

        dr = ds.Tables("Students").NewRow

        dr.Item(1) = "2"
        dr.Item(2) = "3"
        dr.Item(3) = "4"

        ds.Tables(0).Rows.Add(dr)

        If ds.HasChanges(DataRowState.Added) Then
  
            Me.StudentsTableAdapter.Update(ds.Tables("Students").GetChanges(DataRowState.Added))
        End If

       


But that doesn't do anything at all. No data added, no errors.

I have tried updating a datagrid to be told it can't be updated when bound.

I look on google and nothing seems to relate to adding data to an access database when bound to the project through the datasource wizard.

I just want to learn how to do this but am stuck. Please don't say that I should use another method or whatever, I want to learn this way at the moment.

Is This A Good Question/Topic? 0
  • +

Replies To: Adding records to Access database

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9214
  • View blog
  • Posts: 34,612
  • Joined: 12-June 08

Re: Adding records to Access database

Posted 15 May 2011 - 06:47 PM

Confusing issue - why are you doing an update (aka row state = modified) with rowstate=added when a row state=added should be an Insert?
Was This Post Helpful? 0
  • +
  • -

#3 vbnet9  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 346
  • Joined: 26-May 09

Re: Adding records to Access database

Posted 15 May 2011 - 06:49 PM

View Postmodi123_1, on 15 May 2011 - 09:47 PM, said:

Confusing issue - why are you doing an update (aka row state = modified) with rowstate=added when a row state=added should be an Insert?



Because I have no clue what I am doing and can not find it in any books or online how to do it.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9214
  • View blog
  • Posts: 34,612
  • Joined: 12-June 08

Re: Adding records to Access database

Posted 15 May 2011 - 07:16 PM

Odd - what search words are you using? My guess is you are not using the right 'magic words' because this is a pretty standard function.

With adapters it you don't even need to specify the row type - the preconfigged adapters know that:
row state added = use the insert
row state delete = use the delete
row state modified = use the update


There are some tutorials here about the subject:

http://www.dreaminco...ew-with-access/
http://www.dreaminco...imple-database/
Was This Post Helpful? 0
  • +
  • -

#5 Nitwit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 24-January 12

Re: Adding records to Access database

Posted 24 January 2012 - 10:49 AM

View Postmodi123_1, on 15 May 2011 - 07:16 PM, said:

Odd - what search words are you using? My guess is you are not using the right 'magic words' because this is a pretty standard function.

With adapters it you don't even need to specify the row type - the preconfigged adapters know that:
row state added = use the insert
row state delete = use the delete
row state modified = use the update


There are some tutorials here about the subject:

http://www.dreaminco...ew-with-access/
http://www.dreaminco...imple-database/

Did you ever program one line of code? 'Magic words' may be used by magicians, but seldom if ever, solve problems while programming. Bet your name is David Copperfield.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9214
  • View blog
  • Posts: 34,612
  • Joined: 12-June 08

Re: Adding records to Access database

Posted 24 January 2012 - 11:16 AM

Oh the lost joys of a simple 'figure of speech'. :rolleyes:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1