insert命令的问题

howie 2003-05-28 05:44:56
我要在表里加入一条记录
thisCommand.CommandText = @"Insert Into History (Date, Time, Info) " +
@"Values (date, time, r.DecisionResult.Text)";
说命令有语法错误 不知道是为什么

谢谢大家了
Date, Time, Info 和 date, time都是string 格式
...全文
123 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
howie 2003-05-31
  • 打赏
  • 举报
回复
果真是关键字冲突
我寒…………
angelior 2003-05-29
  • 打赏
  • 举报
回复
Knight94(愚翁)的有己將你兩種情況都說了!
看來你也OK了!
:)
你可以debug時查看你要的結果,最簡單是MessageBox.Show(thisCommand.CommandText.ToString());看一下符合語法規范不!

如果date和time直接是要插入的数据话,而不是参数,可以如下:
thisCommand.CommandText = @"Insert Into History (Date, Time, Info) " +
@"Values ('date', 'time', '"+r.DecisionResult.Text+"')";

如果date和time是自己的字符变量,可以如下:
thisCommand.CommandText = @"Insert Into History (Date, Time, Info) " +
@"Values ('"+date
+"', '"+time+"', '"+r.DecisionResult.Text+"')";
kittyfish 2003-05-29
  • 打赏
  • 举报
回复
同意楼上的看法。
应该是关键字的问题。
数据库的字段最好使用dates,times,names
我曾经在用access时,因为name与关键字冲突而出错。
Knight94 2003-05-29
  • 打赏
  • 举报
回复
如果上面成功,说明字段名与数据库的关键字冲突了。
如果还不行,用"insert into History (data, time, info) values ( '...' , '...' , '...')"直接在工具中进行插入,看是否成功。
Knight94 2003-05-29
  • 打赏
  • 举报
回复
Try this:
thisCommand.CommandText = @"Insert Into History ([Date], [Time], Info) " +
@"Values ('"+date
+"', '"+time+"', '"+r.DecisionResult.Text+"')";
howie 2003-05-29
  • 打赏
  • 举报
回复
to : Knight94(愚翁)

date 和 time 都是字符串变量
我试过第二种方法 还是语法错误

to dlmu2001(vcfan)
我跟进去了 commandtext的内容是
"insert into History (data, time, info) values ( '...' , '...' , '...')"
字符串的地方我用。。。代替了
Knight94 2003-05-29
  • 打赏
  • 举报
回复
To thisCommand.CommandText = @"Insert Into History (Date, Time, Info) " +
@"Values (date, time, r.DecisionResult.Text)";

如果date和time直接是要插入的数据话,而不是参数,可以如下:
thisCommand.CommandText = @"Insert Into History (Date, Time, Info) " +
@"Values ('date', 'time', '"+r.DecisionResult.Text+"')";

如果date和time是自己的字符变量,可以如下:
thisCommand.CommandText = @"Insert Into History (Date, Time, Info) " +
@"Values ('"+date
+"', '"+time+"', '"+r.DecisionResult.Text+"')";
红心地瓜 2003-05-28
  • 打赏
  • 举报
回复
跟进去,看看你的thisCommand.CommandText 的值,然后把它放到Sql Server中调试一下
howie 2003-05-28
  • 打赏
  • 举报
回复
TO sim(船长)
r.DecisionResult.Text是一个RICHEDIT的内容
我把它保存在数据库里 相当于一个日志
date和time都是字符串形式 来表示时间
我用了TOSTRING来形成的

TO ocoogo(殴酷哥), PoorAngel(安琪儿),suosuoyyy(羊羊)
我都试过了,都不成
我严格按照SDK的帮助文件里INSERT的格式去写,还是有语法错误,不知道为什么
只是那里没有变量而已,可加了'也不成
ocoogo 2003-05-28
  • 打赏
  • 举报
回复
@"Insert Into History (Date, Time, Info) Values ('"+date+"','"+ time+"','"+ r.DecisionResult.Text+"')";
PoorAngel 2003-05-28
  • 打赏
  • 举报
回复
thisCommand.CommandText = @"Insert Into History (Date, Time, Info) Values (date, time, r.DecisionResult.Text)";
suosuoyyy 2003-05-28
  • 打赏
  • 举报
回复
thisCommand.CommandText = "Insert Into History (Date, Time, Info)
Values (date, time, '"+r.DecisionResult.Text+"')";
sim 2003-05-28
  • 打赏
  • 举报
回复
还有你的data,time是什么?
sim 2003-05-28
  • 打赏
  • 举报
回复
r.DecisionResult.Text 是什么?

110,567

社区成员

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

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

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