Pb mise à jour Access database depuis C# ASPX ?

D

Dominique

Bonjour,

j'ai des bases de données Access ou je veux ajouter des enregistrements.
La procédure suivante marche sur une base, et pas sur l'autre retournant
l'erreur ci apres :

Ne génère pas d'erreur
System.Data.DataRow newrow = dataSetMembres1.Membres.NewRow() ;
newrow["email"] = EditEmail.Text ;
newrow["Nom"] = EditNom.Text ;
newrow["Prenom"] = EditPrénom.Text ;
.....
dataSetMembres1.Membres.Rows.Add(newrow) ;
oleDbDataAdapterMembres.Update(dataSetMembres1.Membres) ;

Génère une erreur

System.Data.DataRow newrow = dataSetMembres1.Saclay.NewRow() ;
newrow["email"] = EditEmail.Text ;
newrow["Nom"] = EditNom.Text ;
newrow["Prenom"] = EditPrénom.Text ;
newrow["Laboratoire"] = EditLabo.Text ;
newrow["Ville"] = EditVille.Text ;
if (EditTitre.Text!="")
newrow["Titre"] = EditTitre.Text ;
dataSetMembres1.Saclay.Rows.Add(newrow) ;
oleDbDataAdapterMembres.Update(dataSetMembres1.Saclay) ; // Génère
l'erreur

Les deux bases de données ont été générées de la meme façon (c'est même un
copie de la première) avec ajout d'un champ mémo.
Les connexions sont faites sans erreur par Visual Studio (drag depuis
serveur) et résident dans le même fichier .mbd. Les schémas sont ok.

Description : Une exception non gérée s'est produite au moment de
l'exécution de la demande Web actuelle. Contrôlez la trace de la pile pour
plus d'informations sur l'erreur et son origine dans le code.

Détails de l'exception: System.Data.OleDb.OleDbException: Le paramètre ?_1
n'a pas de valeur par défaut.

Erreur source:

Ligne 517 :// newrow["Type_de_navigateur"] = Request.UserAgent ;
Ligne 518 : dataSetMembres1.Saclay.Rows.Add(newrow) ;
Ligne 519 : oleDbDataAdapterMembres.Update(dataSetMembres1.Saclay) ;
Ligne 520 : }
Ligne 521 :

Fichier source : d:\web\inetpub\gbp\controls\enregistrejournee.ascx.cs
Ligne : 519

Trace de la pile:

[OleDbException (0x80040e10): Le paramètre ?_1 n'a pas de valeur par
défaut.]
System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping) +1662
System.Data.Common.DbDataAdapter.Update(DataTable dataTable) +139
rmngbp.Controls.EnregistreJournee.UpdateJournee() in
d:\web\inetpub\gbp\controls\enregistrejournee.ascx.cs:519
rmngbp.Controls.EnregistreJournee.ValidButton_Click(Object sender,
EventArgs e) in d:\web\inetpub\gbp\controls\enregistrejournee.ascx.cs:543
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +108
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1292




Merci d'avance si vous avez des idées...

Dominique
 
C

Cor Ligthert

Dominique,

Do you have a primary key field in your datarow, and which is that than?
I have the idea that that is missing.


Cor
 
D

Dominique

Yes I have a primary key named Identificateur in both cases
+ it appears with a key in Access display
+ it appears also in the xsd schema

Dominique
 
C

Cor Ligthert

Dominique,

Maybe makes showing your select string it easier to help.

When I read it well, than there is told that the parameter 1 is not ok is
that right?

Cor
 
D

Dominique

Here are the UpdateCommand strings, automatically generated by Visual
Studio.. there is no trace of _1...



The one that works

this.oleDbUpdateCommand2.CommandText = @"UPDATE Membres SET [Count] = ?,
[Date_de_dernière_modification] = ?, email = ?, idLabo = ?, Laboratoire = ?,
Nom = ?, [Nom_de_l'ordinateur_distant] = ?, [Nom_d'utilisateur] = ?, Prenom
= ?, Type_de_navigateur = ?, Valid = ?, Ville = ? WHERE (Identificateur = ?)
AND ([Count] = ? OR ? IS NULL AND [Count] IS NULL) AND
([Date_de_dernière_modification] = ? OR ? IS NULL AND
[Date_de_dernière_modification] IS NULL) AND (Laboratoire = ? OR ? IS NULL
AND Laboratoire IS NULL) AND (Nom = ? OR ? IS NULL AND Nom IS NULL) AND
([Nom_d'utilisateur] = ? OR ? IS NULL AND [Nom_d'utilisateur] IS NULL) AND
([Nom_de_l'ordinateur_distant] = ? OR ? IS NULL AND
[Nom_de_l'ordinateur_distant] IS NULL) AND (Prenom = ? OR ? IS NULL AND
Prenom IS NULL) AND (Type_de_navigateur = ? OR ? IS NULL AND
Type_de_navigateur IS NULL) AND (Valid = ?) AND (Ville = ? OR ? IS NULL AND
Ville IS NULL) AND (email = ? OR ? IS NULL AND email IS NULL) AND (idLabo =
? OR ? IS NULL AND idLabo IS NULL)";

The one that does not work...

this.oleDbUpdateCommand3.CommandText = @"UPDATE SaclayJuin2005 SET Adresse =
?, Adresse2 = ?, CodePostal = ?, [Date_de_dernière_modification] = ?, email
= ?, Fax = ?, Laboratoire = ?, Modification = ?, Nom = ?,
[Nom_de_l'ordinateur_distant] = ?, [Nom_d'utilisateur] = ?, Prenom = ?, Tel
= ?, Titre = ?, Type_de_navigateur = ?, Ville = ? WHERE (Identificateur = ?)
AND (Adresse = ? OR ? IS NULL AND Adresse IS NULL) AND (Adresse2 = ? OR ? IS
NULL AND Adresse2 IS NULL) AND (CodePostal = ? OR ? IS NULL AND CodePostal
IS NULL) AND ([Date_de_dernière_modification] = ? OR ? IS NULL AND
[Date_de_dernière_modification] IS NULL) AND (Fax = ? OR ? IS NULL AND Fax
IS NULL) AND (Laboratoire = ? OR ? IS NULL AND Laboratoire IS NULL) AND
(Modification = ? OR ? IS NULL AND Modification IS NULL) AND (Nom = ? OR ?
IS NULL AND Nom IS NULL) AND ([Nom_d'utilisateur] = ? OR ? IS NULL AND
[Nom_d'utilisateur] IS NULL) AND ([Nom_de_l'ordinateur_distant] = ? OR ? IS
NULL AND [Nom_de_l'ordinateur_distant] IS NULL) AND (Prenom = ? OR ? IS NULL
AND Prenom IS NULL) AND (Tel = ? OR ? IS NULL AND Tel IS NULL) AND
(Type_de_navigateur = ? OR ? IS NULL AND Type_de_navigateur IS NULL) AND
(Ville = ? OR ? IS NULL AND Ville IS NULL) AND (email = ? OR ? IS NULL AND
email IS NULL)";
 
C

Cor Ligthert

Dominique,

Why you show the update string while I ask for the Select String?

Cor
 
D

Dominique

Here are the Select Commands :

the one which works

this.oleDbSelectCommand2.CommandText = "SELECT [Count],
[Date_de_dernière_modification], email, Identificateur, idLabo, L" +
"aboratoire, Nom, [Nom_de_l\'ordinateur_distant], [Nom_d\'utilisateur],
Prenom, Typ" +
"e_de_navigateur, Valid, Ville FROM Membres";

The one which does not work

this.oleDbSelectCommand3.CommandText = "SELECT Adresse, Adresse2,
CodePostal, [Date_de_dernière_modification], email, Fax" +
", Identificateur, Laboratoire, Modification, Nom,
[Nom_de_l\'ordinateur_distant]," +
" [Nom_d\'utilisateur], Prenom, Tel, Titre, Type_de_navigateur, Ville
FROM SaclayJ" +
"uin2005";
 
C

Cor Ligthert

What I don't understand is why the tablename is

SaclayJuin2005 you are able to use

System.Data.DataRow newrow = dataSetMembres1.Saclay.NewRow() ;

Cor
 
D

Dominique

Ok I did several trials with different names and it is just a renaming..

I cannot solve this problem and I skip for now.

Thanks for your efforts and advices

Dominqiue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top