sql插入日期语法错误

stevenjin 2020-09-22 05:13:13
这时哪写错了,报语法错误
int res2 = db.Ado.ExecuteCommand($"INSERT INTO TransHistory(Tel,OutAmount,CreateDate) VALUES({Tel},{OutSum},'{DateTime.Now.ToShortDateString().ToString()}'");
...全文
8099 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
正怒月神 2020-09-23
  • 打赏
  • 举报
回复
#2正解,最后少了个括号。
一叶知秋~ 2020-09-23
  • 打赏
  • 举报
回复
int res2 = db.Ado.ExecuteCommand($"INSERT INTO TransHistory(Tel,OutAmount,CreateDate) VALUES('{Tel}',{OutSum},'{DateTime.Now.ToString("yyyy-MM-dd")}'");
lion_zxb 2020-09-23
  • 打赏
  • 举报
回复
字符串类型的‘{0}’就加引号,数值类型,就不要加引号{0}。
lion_zxb 2020-09-23
  • 打赏
  • 举报
回复
string Tel = "010-88888888"; decimal OutAmount = 88888; string time=DateTime.Now.ToShortDateString().ToString(); string strsql= string.Format((@"INSERT INTO TransHistory(Tel,OutAmount,CreateDate) VALUES ('{0}',{1},'{2}')"), Tel, OutAmount, time); int res2 = db.Ado.ExecuteCommand(strsql);
lion_zxb 2020-09-23
  • 打赏
  • 举报
回复
string Tel = "010-88888888"; decimal OutAmount = 88888; string time=DateTime.Now.ToShortDateString().ToString(); string strsql= string.Format((@"INSERT INTO TransHistory(Tel,OutAmount,CreateDate) VALUES ({0},{1},'{2}')"), Tel, OutAmount, time); int res2 = db.Ado.ExecuteCommand(strsql);
Bridge_go 2020-09-22
  • 打赏
  • 举报
回复
你最后好像少了一个括号 int res2 = db.Ado.ExecuteCommand($"INSERT INTO TransHistory(Tel,OutAmount,CreateDate) VALUES({Tel},{OutSum},'{DateTime.Now.ToShortDateString().ToString()}')");
Bridge_go 2020-09-22
  • 打赏
  • 举报
回复
CreateDate什么类型的

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧