我有一个表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
但是当我手动运行查询时,它会完全保存
答案 0 :(得分:0)
您的列大小可能太小,然后您的插入被截断。尝试将列查询调整为ITL_ReportLog表,或尝试修剪变量
答案 1 :(得分:0)
在插入代码之前,尝试将单引号字符替换为其他字符。稍后使用替换功能更新它。