我使用 C# 4.0 和 SQL server 2008 R2 我有一个像这样的 C# 脚本:
string sSql = "";
foreach (var oItem in LeListVoit_End)
{
//insert into Lettrvoit
if (sSql != "") sSql += " UNION ALL ";
sSql += "SELECT '" + oItem.IdLettre + "', '" + oItem.FaClient +"', '" + oItem.Date_Cloture + "', '" + oItem.CodeDest + "', '" + oItem.ModalMode + "', '" + oItem.LibPort + "', '" + oItem.LibExpr + "', '" + oItem.LibUnite + "', '" + oItem.EnlvUnite + "', '" + oItem.NbrColis + "', '" + oItem.Poids.ToString().Replace(',', '.') + "', '" + oItem.LeCR.ToString().Replace(',', '.') + "', '" + oItem.LeVD.ToString().Replace(',', '.') + "', '" + oItem.CodeClient + "', '"
+ oItem.RsNom_Exp.Replace("'", " ") + "', '" + oItem.Addr_Exp.Replace("'", " ") + "', '" + oItem.CP_Exp + "', '" + oItem.Ville_Exp.Replace("'", " ") + "', '" + oItem.Tel_Exp + "', '" + oItem.Fax_Exp + "', '"
+ oItem.RsNom_Dest.Replace("'", " ") + "', '" + oItem.Addr_Dest.Replace("'", " ") + "', '" + oItem.CP_Dest + "', '" + oItem.Ville_Dest.Replace("'", " ") + "', '" + oItem.Tel_Dest + "', '" + oItem.Fax_Dest + "', '" + oItem.InseeDest + "', '"
+ Is_Print + "', '" + CHAUFFEUR + "', '" + oItem.Transporteur + "', '" + oItem.NoOrdreCumul + "', '" + oItem.CodeMag + "', '" + oItem.Facturation + "', '" + oItem.IsLiv_sign + "', '" + oItem.IsLiv_Samedi + "', '" + oItem.Observ + "', '" + oItem.LeAgence + "', '" + oItem.LibTourne + "', '" + oItem.Date_Clot_Reel + "'";
}
string sqlComm_Insert = "INSERT INTO LETTRE_VOIT_FINAL ([NOID],FA_CLIENT, [DATE_CLOTURE], [CODE_DEST] ,[MODAL_MODE], [LIBELLE_PORT] ,[LIBELLE_EXPR], [LIBELLE_UNITE],ENLEV_UNITE, [NBR_COLIS], [POID], [ENLEV_CREMB], [ENLEV_DECL], CODE_CLIENT, [RS_NOM_EXP] ,[ADDR_EXP] ,[CP_EXP] ,[VILLE_EXP] ,[TEL_EXP] ,[FAX_EXP],[RS_NOM_DEST] ,[ADDR_DEST] ,[CP_DEST] ,[VILLE_DEST] ,[TEL_DEST] ,[FAX_DEST],INSEE_DEST, IS_PRINT, CHAUFFEUR, TRANSPORTEUR, NO_ORDRE_CUMMUL, CODE_MAG, FACTURATION, LIVRS_SIGN, LIVRS_SAMD, OBS, LIB_AGENCE, LIB_TOURNE, DATE_CLOTUR_REEL) " + sSql;
SqlCommand comm_Insert = new SqlCommand(sqlComm_Insert, connectionWrapper.conn);
comm_Insert.ExecuteScalar();
它运行良好,但我在调试时错过了 oItem.Date_Clot_Reel 的毫秒值,我得到了 '2013-03-19 16:02:18.807'
但是在我运行这个 sql 之后,我得到了 '2013-03-19 16:02:18.000'
我怎么能错过毫秒807?
提前谢谢你
PS:也许当我使用它时效果很好
comm_Insert.Parameters.AddWithValue("@NDATE_CLOTURE_REEL", oItem.Date_Clot_Reel);
但是当我这样使用时,我无法使用 sSql += " UNION ALL ";