[VB2008 - Stupid] Add new record to accdb database

E

.-=] ExTrEmE [=-.

Hi all!

I need an help for a stupid thing.. sorry but I'm a newbie on .net.

- Access 2007 DB is connected by wizard (CustomersSheetsDadaSet)
- Each table has insert,update,delete,select commands in sql defined at
design time (customers, invoices, payments)
- I've a small amount of textboxes, datetimepicker and so on *unbounded*.

The problem is very simple: no record where added to the database :(

I fill all the required data, then press a button that add the new record to
invoices table in the DB.
No errors, no exeptions, nothing.. but no new record into the db :( :( :(

I simply try to add the record with:

Try
InvoicesTableAdapter.Insert(*all my fields*)
Catch ex As exception
msgbox("Bad",ex.message)
End Try

No error.. but no new record :(

I've made a second test with these lines of code (obviously with no result
:( ):

Dim NewInvoice As CustomersSheetsDadaSet.FattureRow

NewInvoice = CustomersSheetsDadaSet.Fatture.NewRow
NewInvoice.CustomerCode = ElencoFornitori.SelectedValue 'List bounded with
customers table
NewInvoice.InvoiceNumber = txtNumeroFattura.Text
NewInvoice.EmissionDate = dtpDataEmissione.Value
NewInvoice.ExpireOn = dtpDataScadenza.Value
NewInvoice.Euros = txtImporto.Text
NewInvoice.Description = txtDescrizione.Text

CustomersSheetsDadaSet.Invoices.Rows.Add(NewInvoice)
CustomersSheetsDadaSet.Invoices.DataSet.AcceptChanges()

I don't know what I need to do.
Can you help me?

Thanks.
 
C

Cor Ligthert[MVP]

Hi,

You write I don't know what I need to do,

First of all use a decent name, probably then you have more change somebody
helps you because your message is not seen as spam.

Secondly, have you any idea what the acceptchanges means. Some keywords are
just abbrevations, the ones which have given in my idea the most confusing
were after the dispose (dispose unmanaged resources) the acceptchanges,
which means accept the changes as done and set the datarow(s) to unchanged
or if they are deleted, remove those. (Be aware also that there is a
distinct between remove and delete in a dataset).

remove that acceptchanges.

And then do the TableAdapter.Update which will only handle inserted, changed
or deleted datarows.
(the update does automaticly the acceptchanges)

Cor
 
E

.-=] ExTrEmE [=-.

Cor Ligthert said:
Hi,
You write I don't know what I need to do,
First of all use a decent name, probably then you have more change
somebody helps you because your message is not seen as spam.

Sorry for names.. I've translated "on the fly" the code before post the
message (italian names), but i miss to translate the textbox e datetime
controls :)
Secondly, have you any idea what the acceptchanges means. Some keywords
are just abbrevations, the ones which have given in my idea the most
confusing

According to the documentation, I understand that AcceptChanges is used to
commit all the changes for the dataset from the last acceptchanges call.
It's wrong? :-?
were after the dispose (dispose unmanaged resources) the acceptchanges,
which means accept the changes as done and set the datarow(s) to unchanged
or if they are deleted, remove those. (Be aware also that there is a
distinct between remove and delete in a dataset).

Ok.. so..
acceptchanges = commit all the changes on the dataset but NOT on the
fisical DB, right?
remove that acceptchanges.
Ok.

And then do the TableAdapter.Update which will only handle inserted,
changed or deleted datarows.
(the update does automaticly the acceptchanges)

I've removed acceptchanges, but the problem remain.
My new record not were added to the accdb file. :(
Using CustomersSheetsDadaSet.Invoices.Rows.Add(NewInvoice) or using Insert
method to add new record.. does not change the result :(

Thanks for reply.
Simone

.-=] ExTrEmE [=-. said:
Hi all!

I need an help for a stupid thing.. sorry but I'm a newbie on .net.

- Access 2007 DB is connected by wizard (CustomersSheetsDadaSet)
- Each table has insert,update,delete,select commands in sql defined at
design time (customers, invoices, payments)
- I've a small amount of textboxes, datetimepicker and so on *unbounded*.

The problem is very simple: no record where added to the database :(

I fill all the required data, then press a button that add the new record
to invoices table in the DB.
No errors, no exeptions, nothing.. but no new record into the db :( :( :(

I simply try to add the record with:

Try
InvoicesTableAdapter.Insert(*all my fields*)
Catch ex As exception
msgbox("Bad",ex.message)
End Try

No error.. but no new record :(

I've made a second test with these lines of code (obviously with no
result :( ):

Dim NewInvoice As CustomersSheetsDadaSet.FattureRow

NewInvoice = CustomersSheetsDadaSet.Fatture.NewRow
NewInvoice.CustomerCode = ElencoFornitori.SelectedValue 'List bounded
with customers table
NewInvoice.InvoiceNumber = txtNumeroFattura.Text
NewInvoice.EmissionDate = dtpDataEmissione.Value
NewInvoice.ExpireOn = dtpDataScadenza.Value
NewInvoice.Euros = txtImporto.Text
NewInvoice.Description = txtDescrizione.Text

CustomersSheetsDadaSet.Invoices.Rows.Add(NewInvoice)
CustomersSheetsDadaSet.Invoices.DataSet.AcceptChanges()

I don't know what I need to do.
Can you help me?

Thanks.
 
C

Cor Ligthert[MVP]

Can you show how you have place the DataAdapter.Update after that you have
added that new row to the datatable?

Cor

.-=] ExTrEmE [=-. said:
Cor Ligthert said:
Hi,
You write I don't know what I need to do,
First of all use a decent name, probably then you have more change
somebody helps you because your message is not seen as spam.

Sorry for names.. I've translated "on the fly" the code before post the
message (italian names), but i miss to translate the textbox e datetime
controls :)
Secondly, have you any idea what the acceptchanges means. Some keywords
are just abbrevations, the ones which have given in my idea the most
confusing

According to the documentation, I understand that AcceptChanges is used to
commit all the changes for the dataset from the last acceptchanges call.
It's wrong? :-?
were after the dispose (dispose unmanaged resources) the acceptchanges,
which means accept the changes as done and set the datarow(s) to
unchanged or if they are deleted, remove those. (Be aware also that there
is a distinct between remove and delete in a dataset).

Ok.. so..
acceptchanges = commit all the changes on the dataset but NOT on the
fisical DB, right?
remove that acceptchanges.
Ok.

And then do the TableAdapter.Update which will only handle inserted,
changed or deleted datarows.
(the update does automaticly the acceptchanges)

I've removed acceptchanges, but the problem remain.
My new record not were added to the accdb file. :(
Using CustomersSheetsDadaSet.Invoices.Rows.Add(NewInvoice) or using Insert
method to add new record.. does not change the result :(

Thanks for reply.
Simone

.-=] ExTrEmE [=-. said:
Hi all!

I need an help for a stupid thing.. sorry but I'm a newbie on .net.

- Access 2007 DB is connected by wizard (CustomersSheetsDadaSet)
- Each table has insert,update,delete,select commands in sql defined at
design time (customers, invoices, payments)
- I've a small amount of textboxes, datetimepicker and so on
*unbounded*.

The problem is very simple: no record where added to the database :(

I fill all the required data, then press a button that add the new
record to invoices table in the DB.
No errors, no exeptions, nothing.. but no new record into the db :( :(
:(

I simply try to add the record with:

Try
InvoicesTableAdapter.Insert(*all my fields*)
Catch ex As exception
msgbox("Bad",ex.message)
End Try

No error.. but no new record :(

I've made a second test with these lines of code (obviously with no
result :( ):

Dim NewInvoice As CustomersSheetsDadaSet.FattureRow

NewInvoice = CustomersSheetsDadaSet.Fatture.NewRow
NewInvoice.CustomerCode = ElencoFornitori.SelectedValue 'List bounded
with customers table
NewInvoice.InvoiceNumber = txtNumeroFattura.Text
NewInvoice.EmissionDate = dtpDataEmissione.Value
NewInvoice.ExpireOn = dtpDataScadenza.Value
NewInvoice.Euros = txtImporto.Text
NewInvoice.Description = txtDescrizione.Text

CustomersSheetsDadaSet.Invoices.Rows.Add(NewInvoice)
CustomersSheetsDadaSet.Invoices.DataSet.AcceptChanges()

I don't know what I need to do.
Can you help me?

Thanks.
 
K

Kevin S Gallagher

Best guess is you need to setup the database you are working with in
"Security Center."
http://office.microsoft.com/en-us/help/HA100337761033.aspx#12
Let's say your database is in the folder C:\Databases but this path is not
setup
under Trust Center as per the link above, any attempts to add a record will
be denied
without any exceptions being thrown. Once you have either add C:\Databases
to the
Trust Center, place the database in a known trusted location or use a
certificate you
can then add a new record.
 
E

.-=] ExTrEmE [=-.

Many thanks to all for support.

At this time.. I don't know why.. but it work.

Not a trusting issue, not a coding issue.

In previous attempts, after code corrections like suggested, the database
was not updated during debug (db in the debug folder)
This evening I've tried to run the compiled exe from release folder and the
database was updated!!!!

From that time.. also the db in the debug folder is regulary updated during
debug.

So... many thanks again for support!

Simone
 
Top