Problème data tramsmission from tableadapter to ACCESS database

  • Thread starter Thread starter philip
  • Start date Start date
P

philip

On a form, I have a datagridview.
This datagridview is constructed on a dataset filled by a tableadapter.
The table adapter do very well what it must do when filling dataset.
Insertions, modifications and deletions functions very well in the dataset.
But impossible to transmit modifications in ACCESS database. Impossible to
WRITE in database.

Here is the code for data transmission from tableadapter to Access database
:

Private Sub ArtistesBindingNavigatorSaveItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ArtistesBindingNavigatorSaveItem.Click
Try
Me.Validate()
Me.ArtistesBindingSource.EndEdit()
Me.ArtistesTableAdapter.Update(Me.StarDvdDataDataSet.artistes)
System.Windows.Forms.MessageBox.Show("Success !")
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub

Program says "Success !" but nothing has changed in access database.

May be I am stupid, but I don't understand !

Please help me.
Excuse me for my english. I'm french.
 
Philip,

There are not much people who write "probleme" as you do. However this is an
International newsgroup, so we understand a lot even if it is in not correct
English.

What you probably need is just the endcurrentedit, that pushes the data down
in the datasource.

Probably with your strongly typed dataset if that is the datasource.

BindingContext(StarDvdDataDataSet.artistes).EndCurrentEdit()

I hope this helps,

Cor
 
Thanks for uyour help

I added the line : Me.BindingContext(EssaiBindingSource).EndCurrentEdit() to
try if "Me.EssaiBindingSource.EndEdit()
" is not enough :

Private Sub EssaiBindingNavigatorSaveItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
EssaiBindingNavigatorSaveItem.Click
Try
Me.Validate()
Me.EssaiBindingSource.EndEdit()
Me.BindingContext(EssaiBindingSource).EndCurrentEdit()
Me.EssaiTableAdapter.Update(Me.Bd11DataSet.essai)
System.Windows.Forms.MessageBox.Show("Success !")
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub

Nothing happened. Access database has not changed. Modifications are always
good in dataset, but not transmitted to Access Dababase.

And this time, I use a very little database with only one table with only
three fields : 1 autoincrement field, ans 2 text fields.
And there is one row (line) of data in table, writen directly in Access
(because I cannot do it in Visual Studio 2005).
I have created this database specially for resolving my problem, to be sure
that no relation troubled the process.

Curious thing :
One of the two text fields are declared as unique (both in Access database,
and dataset structure in vsstudio).
My table as only one line ans I try to add a new line. If I write a line
with the same value as the first for this unique field, I have the waited
message "Column 'Nom' is constrained to be unique".
If I give 'false' to the unique property of this field in Dataset Designer,
letting unique in Access table, I have the message of Access (in french,
it's a french version of Access) : "Risque de doublons". Access detects the
unique problem. So he TRIES to write in database.

BUT IT'S IMPOSSIBLE TO WRITE A SECOND LINE IN TABLE from Visual Studio 2005,
EVEN IF I GIVE GOOD DATA (not unique) FOR THE SECOND LINE.
The Dataset creates line, takes data, but tableAdapter cannot write it in
database.

Do you see another reason for this impossibility to write in database ?

If someone of Microsoft can examine the problem, he is welcome. Because
today I don't like Microsoft. -)
 
Philip,

Did you try what I wrote as well?

Cor

philip said:
Thanks for uyour help

I added the line : Me.BindingContext(EssaiBindingSource).EndCurrentEdit()
to try if "Me.EssaiBindingSource.EndEdit()
" is not enough :

Private Sub EssaiBindingNavigatorSaveItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
EssaiBindingNavigatorSaveItem.Click
Try
Me.Validate()
Me.EssaiBindingSource.EndEdit()
Me.BindingContext(EssaiBindingSource).EndCurrentEdit()
Me.EssaiTableAdapter.Update(Me.Bd11DataSet.essai)
System.Windows.Forms.MessageBox.Show("Success !")
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub

Nothing happened. Access database has not changed. Modifications are
always good in dataset, but not transmitted to Access Dababase.

And this time, I use a very little database with only one table with only
three fields : 1 autoincrement field, ans 2 text fields.
And there is one row (line) of data in table, writen directly in Access
(because I cannot do it in Visual Studio 2005).
I have created this database specially for resolving my problem, to be
sure that no relation troubled the process.

Curious thing :
One of the two text fields are declared as unique (both in Access
database, and dataset structure in vsstudio).
My table as only one line ans I try to add a new line. If I write a line
with the same value as the first for this unique field, I have the waited
message "Column 'Nom' is constrained to be unique".
If I give 'false' to the unique property of this field in Dataset
Designer, letting unique in Access table, I have the message of Access (in
french, it's a french version of Access) : "Risque de doublons". Access
detects the unique problem. So he TRIES to write in database.

BUT IT'S IMPOSSIBLE TO WRITE A SECOND LINE IN TABLE from Visual Studio
2005, EVEN IF I GIVE GOOD DATA (not unique) FOR THE SECOND LINE.
The Dataset creates line, takes data, but tableAdapter cannot write it in
database.

Do you see another reason for this impossibility to write in database ?

If someone of Microsoft can examine the problem, he is welcome. Because
today I don't like Microsoft. -)
 
Yes I tried what you write, adding the line you asked me to add when I add
"Me.BindingContext essaiBindingSource).EndCurrentEdit()"
No ?
With this line, I push the data down in the datasource.
But data doesn't modify Access Database.
I'm always to the same point.
Is this problem appearing for the first time, or is it a common problem ?
Thanks for your response.

Philip
 
I seen on Google what MVP means.
Congratulations. I did not know
I work with Access for many years.
I believed that I understood the new concept of dataset and tableadapter,
but my problem reveals that I did not understand anything.
I think dotnet and specially vsstudio 2005 is a very good thing, but I need
to write in a database really a first time at least to continue seriously to
work with this new technology.

Philip
 
Philip,

I wrote this one.
Yes I tried what you write, adding the line you asked me to add when I add
"Me.BindingContext essaiBindingSource).EndCurrentEdit()"

BindingContext(StarDvdDataDataSet.artistes).EndCurrentEdit()

I am curious what it says when it does not accept that one?

Cor
 
He accepts this line : "Me.BindingContext
essaiBindingSource).EndCurrentEdit()"
But nothing happens.
Message box gives me the message "Success", but nothing is written in Access
Database.
No error message. Simply nothing happens in database.

Philip
 
Philip,

You did not try it as I wrote.

The bindingContext is a collection of bindings. If you tell that one of
those has an endCurrentEdit, than he will accept it. However it does than
nothing at your datatable that you want to update as that is not the same.

What is the DataSource property of your datagridview, than I can probably
write the code exact

Cor
 
The datasource property of the datagridview is 'EssaiBindingSource'

When I drag the table 'Essai' on a form, vsStudio 2005 create a
datagridview1
He creates a bd11Dataset, an EssaibindingSource, an EssaiTableAdapter, and
an EssaiBindingNavigator.
Precision for you to give context.
For information, the connectionstring of database is
'Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\vb2005\WindowsApplication1\WindowsApplication1\bd11.mdb'

Thanks for your attention.

Philip
 
Philip,

Can you explain a little bit more how you do this, I thought you was
everything doing in code.
When I drag the table 'Essai' on a form, vsStudio 2005 create a
datagridview1
He creates a bd11Dataset, an EssaibindingSource, an EssaiTableAdapter, and
an EssaiBindingNavigator.

You drag from ? .............etc.

Cor
 
- Menu 'File/New project'
- Menu 'Data/Show Data Sourcess'
- Hyperlink 'Add New Data Source'
- I make new connection to Access Dabase following 'Data source
configuration wizard'
- To the end of this process, I take table 'essai' in panel 'Data Sources'
and I drag it and drop on form 'form1'

- VStudio 2005 creates a 'BD11Dataset' based on my Access Database structure
(here a table with an autoincrement field, and two text fields). Property of
BD11Dataset is 'IncludeSchema'

- Then creates a 'EssaiBindingSource' :
DataMember = 'essai'
DataSource = 'Bd11DataSet'

- Then creates a 'EssaiTableAdapter', and a 'EssaiBindingNavigator' whose
BindingSource is 'EssaiBindingSource'

In code of 'EssaiBindingNavigator' I have the following code written not by
me, but by VStudio :

----------------------------------------
Public Class Form1

Private Sub EssaiBindingNavigatorSaveItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
EssaiBindingNavigatorSaveItem.Click
Me.Validate()
Me.EssaiBindingSource.EndEdit()
Me.EssaiTableAdapter.Update(Me.Bd11DataSet.essai)

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Bd11DataSet.essai'
table. You can move, or remove it, as needed.
Me.EssaiTableAdapter.Fill(Me.Bd11DataSet.essai)

End Sub
End Class
-----------------------------------------------------
I added a 'Try-End Try' verification to the 'EssaiBindingNavigatorSaveItem'
subroutine.

The method 'fill' functions perfectly.
The method 'Update' does'nt function.

BUT I created a button on the form with this code, which functions perfectly
:
-------------------------
Using connection As New
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\vb2005\WindowsApplication1\WindowsApplication1\bd11.mdb")

Dim Commnd As New System.Data.OleDb.OleDbCommand("INSERT INTO essai
(nom,prénom) VALUES ('ae','ea')", connection)
Commnd.ExecuteNonQuery()
End Using
------------------------
A line is added to my Access database.
So the problem is not a system problem between Access Database and VStudio.

A lot of thanks to give me your time.
When you think I Exaggerate, say it.
 
Philip,

I have tried exactly the same as you (with employees from northwind in a way
I can do it in code), and it does as well nothing. I never used so far the
designer.

I will see if I can look tomorrow what it does with SQL server to see if
this is an oledb bug.

Cor
 
Philip,

I found it, you have probably while using the wizard told to copy the
database to your project.

If I did not do that, than it was working fine for me.

I hope this helps,

Cor
 
You are a genious ! That works.
My last question :
Why the fact to displace database create this problem ?
The response to this question will do than I shall can avoid a serious error
later.
This is my last question.

But now, I can work on my project.

A great lot of thanks.

Philip
 
Back
Top