请大家看看这条语句有什么错误?

xxsteven 2003-06-29 05:04:54
Query1.Close;
Query1.Sql.Clear;
Query1.Sql.Add('SELECT * from main');
if ComboBox3.Text<>'' then
Query1.SQL.Add('where nsmc='''+ComboBox3.Text+'''');
if ComboBox4.Text<>'' then
Query1.Sql.Add('AND qiyecode='''+ComboBox4.Text+'''');
Query1.Sql.Add(' AND date between '''+
FormatDateTime('yyyy-mm-dd', DateTimePicker1.Date) +''' and '''+
FormatDateTime('yyyy-mm-dd', DateTimePicker2.Date) + '''');
Query1.Open;
ShowMessage('欢迎使用,一共查询到的记录数是:'+IntToStr(Query1.RecordCount));

在时间段那里有错误,不知道为什么?说是类型不匹配
...全文
85 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
tw829 2003-06-29
  • 打赏
  • 举报
回复
up
firetoucher 2003-06-29
  • 打赏
  • 举报
回复
错了,应该是
strwhere:= '';
if ComboBox3.Text<>'' then
strwhere:= strwhere + ' nsmc='''+ComboBox3.Text+'''';
if ComboBox4.Text<>'' then
begin
if strwhere<>'' then
strwhere := strwhere + ' and ';
strwhere:= strwhere + ' qiyecode='''+ComboBox4.Text+''' AND date between '''+
FormatDateTime('yyyy-mm-dd', DateTimePicker1.Date) +''' and '''+
FormatDateTime('yyyy-mm-dd', DateTimePicker2.Date) + '''';
end;
if strwhere<>'' then
Query1.Sql.Add(' where ' + strwhere);
firetoucher 2003-06-29
  • 打赏
  • 举报
回复
var
strwhere:string;
begin
...//前面一样
Query1.Close;
Query1.Sql.Clear;
Query1.Sql.Add('SELECT * from main');

strwhere:= '';
if ComboBox3.Text<>'' then
strwhere:= strwhere + ' nsmc='''+ComboBox3.Text+'''';
if ComboBox4.Text<>'' then
strwhere:= strwhere + 'AND qiyecode='''+ComboBox4.Text+''' AND date between '''+
FormatDateTime('yyyy-mm-dd', DateTimePicker1.Date) +''' and '''+
FormatDateTime('yyyy-mm-dd', DateTimePicker2.Date) + '''';
if strwhere<>'' then
Query1.Sql.Add(' where ' + strwhere);

Query1.Open;
xxsteven 2003-06-29
  • 打赏
  • 举报
回复
你是对的,好象是有问题,我该怎么写这个程序呢?我的想法是他们都是or的关系 ,可以 全部是条件也可以只有一个是条件,怎么写呢?
xxsteven 2003-06-29
  • 打赏
  • 举报
回复
好,我try
firetoucher 2003-06-29
  • 打赏
  • 举报
回复
?没有看出类型匹配的问题啊
1 如果当你的ComboBox3.Text = ''但ComboBox4.Text<>''是肯定出错
2 行末加空格试试
xxsteven 2003-06-29
  • 打赏
  • 举报
回复
怎么没有人说话呢?
xxsteven 2003-06-29
  • 打赏
  • 举报
回复
请大家看看呀

5,930

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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