【发布时间】:2018-03-04 18:25:14
【问题描述】:
我有一个 ITL_ReportLog 表,当我编写命令时,我必须在其中保存每次打印报告的记录
string tempSql = "";
if (logCheck == "true") {
tempSql = reportSql.Replace("'","''");
tempSql = "INSERT INTO ITL_ReportLog ([username],[runOn],[query]) VALUES ('" + nvc["login"] + "','"+DateTime.Now+"','" + tempSql + "')";
cmd = new SqlCommand(tempSql, conn);
cmd.ExecuteNonQuery();
}
conn.Close();
Response.Write(tempSql);
它显示正确的结果,如图所示
但插入后,当我签入 sql 时,它显示一半查询
SELECT
'CARTZ Link' AS CompanyName,'Mezzanine Floor, 23-C, Lane 8,
Sehar Comm. Area Phase 7 DHA Karachi Pakistan'AS CompanyAddress,
'admin' login_user,'crm.cartzlink.local' selhost,'admin' sellogin,
'LEDGER' selreportTitle,'V' selledgerDate,'01-Jul-2015' selfrmDate,
'23-Sep-2017' seltoDate,'' selaccountId,'' selac_accountId_ac,
'' selcity,'' selarea,'' selsalesmanId,'S' seldst,
'A' seldisplayTransaction,'' selgodownId,'D' selsortBy,
'1' selcurrencyId,'gr_lgr_fcr' seltoprint,'Report
但是当我手动运行查询时,它会完美保存
【问题讨论】:
-
你的列可能太小了,那么你的插入被截断了
-
列大小为 4000,顺便说一下 trim 使用 cmd = new SqlCommand(tempSql.Trim(), conn);
标签: c# sql asp.net sql-server visual-studio