将数据从SqlServer数据库导出到Access数据库

时间:2019-06-09 08:48:27

标签: c# sql-server ms-access

我想使用C#将一些数据从Sqlserver数据库传输到Access数据库,在SqlServer db中,我有一个datetime列,其格式为:“ dd / MM / yyyy”。当数据转换为Access时,日期列将采用“ MM / dd / yyyy”之类的格式。我该如何解决这个问题

 AccessInsertCommand.CommandText = string.Format(@" INSERT INTO[Ordonnance]
                                ( [N_Ordonnance], [N_ASS], [NomASS], [PrénomASS], [Cat_ASS], [DateFinContrat], [Nom Ayant], [Prénom Ayant]      
                                    ,[Sexe Ayant], [Date_Naiss] , [Lien Parenté]   , [Date Saisie]   , [Date_Soin], [Pathologie] , [Nom_Méd], [Statut Assurée]
                                    , [Carte N°=], [DateValidation], [DateFinTraiCh], [N_Fact], [Date_Fact] , [N_Bord], [Nom_Phar]                         
                                    ,[Montant], [Nbre Vignettes], [Total], [Nbre Ord])      
                                VALUES(" + Ordonnance.N_ORD.ToString() + ","
                               + Ordonnance.NUM_ASSURE.ToString() + ","
                               + "'" + Ordonnance.NOM_ASSURE.ToString() + "'" + ","
                               + "'" + Ordonnance.PRENOM_ASSURE.ToString() + "'" + ","
                               + "'" + Ordonnance.CAT_ASS.ToString() + "'" + "," +
                               (Ordonnance.DATE_FIN_CONTRAT == "" ? DBNull.Value : ((object)("#" + Ordonnance.DATE_FIN_CONTRAT + "#")))

                               + "," + "'" + Ordonnance.NOM_AYANT_DR.ToString() + "'" + ","
                               + "'" + Ordonnance.PRENOM_AYANT_DR.ToString() + "'" + ","
                               + "'" + (Ordonnance.SEXE.ToString() == "" ? "null" : Ordonnance.SEXE.ToString()) + "'" + ","
                               + (Ordonnance.DATE_NAISS == null ? DBNull.Value : ((object)("#" + Ordonnance.DATE_NAISS + "#"))) +

                               "," + "'" + Ordonnance.LIEN_PARENTE.ToString() + "'" + ","
                               + ("#" + Ordonnance.DATE_SAISIE+"#") +

                               "," + (Ordonnance.DATE_SOINS == null ? DBNull.Value : ((object)("#" + Ordonnance.DATE_SOINS + "#")))

                               + "," +  (Ordonnance.PATHOLOGIE == "" ? "null" : Ordonnance.PATHOLOGIE.ToString()) + ","
                               + "'" + Ordonnance.MEDECIN.ToString() + "'" + ","
                               + "'" + Ordonnance.STATUT_ASSURE.ToString() + "'" + ","
                               + "'" + (Ordonnance.NUM_CARTE_CHRON.Equals("null") ? "null" : ((object)(Ordonnance.NUM_CARTE_CHRON))) + "'" +

                               "," + (Ordonnance.DATE_VALIDATION.Equals("null") ? "null" : ((object)("#" + Ordonnance.DATE_VALIDATION + "#"))) + ","
                               + (Ordonnance.DATE_FIN_TRAITEMENT_CHRON.Equals("null") ? "null" : ((object)("#" + Ordonnance.DATE_FIN_TRAITEMENT_CHRON + "#"))) +

                               "," + (Ordonnance.NUM_FACTURE == null ? DBNull.Value : ((object)(Ordonnance.NUM_FACTURE))) + ","
                               + (Ordonnance.DATE_FACTURE == null ? DBNull.Value : ((object)("#" + Ordonnance.DATE_FACTURE + "#"))) +

                               "," + (Ordonnance.NUM_BORDEREAU == null ? DBNull.Value : ((object)(Ordonnance.NUM_BORDEREAU))) + ","

                               + "'" + Ordonnance.NOM_PHARMACIE.ToString() + "'" + ","
                               + (Ordonnance.MONTANT.ToString()).Replace(",", ".") + ","
                               + Ordonnance.NBR_VIGNETTE.ToString()
                               + "," + "9999999"
                               + "," + Ordonnance.NBRE_ORD.ToString() + ")");
                        AccessInsertCommand.ExecuteNonQuery();

问题是作为对象的“ DateSoin”的格式设置不正确。

0 个答案:

没有答案