新人问个问题

zodiachAries 2016-02-18 12:04:05
System.DateTime currentTime = new System.DateTime();
int 时 = currentTime.Hour;
int 分 = currentTime.Minute;
int 秒 = currentTime.Second;
DateTime dt0 = DateTime.Now;
DateTime dt1 = dt0.AddHours(-2.0);
SqlDataAdapter sda = new SqlDataAdapter("select * from SecurityCheck where Insep ectionBegin = dt1 ",conn);
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds;
有没有大大能给指点下,到底是哪儿有语法问题么orz
...全文
229 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zodiachAries 2016-02-18
  • 打赏
  • 举报
回复
引用 2 楼 duanzi_peng 的回复:
ectionBegin = dt1 -> 这不对。dt1 应该作为一个变量值 传入进来。例如: ectionBegin = '+dt1+'
对的确是这里的问题,非常感谢
just59277 2016-02-18
  • 打赏
  • 举报
回复
Insep 我标记的这个怎么没加黑? 这个不是sqlserver的关键字
just59277 2016-02-18
  • 打赏
  • 举报
回复
1 请贴出你的错误信息 2 自己先调试看看 3针对你这个问题 你可以把sql语句 “select * from SecurityCheck where Insep ectionBegin = dt1 ” 复制到数据库中运行一遍看看结果。 这里 where Insep ectionBegin = dt1 是有问题的吧,参数dt1 这有问题
fudapeng7 2016-02-18
  • 打赏
  • 举报
回复

string sql = string.Format("select * from SecurityCheck where Insep  ectionBegin = {0} ",dt1);
SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
或者这样 一般情况sql语句我都这样弄
exception92 2016-02-18
  • 打赏
  • 举报
回复
ectionBegin = dt1 -> 这不对。dt1 应该作为一个变量值 传入进来。例如: ectionBegin = '+dt1+'
Poopaye 2016-02-18
  • 打赏
  • 举报
回复
那你是怎么知道有语法问题的?

110,539

社区成员

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

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

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