两个小小小小小问题

ngyxh 2003-06-04 02:37:41
1/日期型字段不能作为条件吗?
select sum(字段名) as getsum from tablename where 日期>2003-6-1 时就会出现:"Type mismatch in expression."怎么解决啊?
2/在DBGrid中,怎样输入第一个字段时第二个字段就会自动的填上第一个字段的前三个字符啊。如第一字段输入"10055",确认后,第二个字段就自动的填上数据"100"。

最好能写详细一点.举个例子.
...全文
32 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
cow8063 2003-06-04
  • 打赏
  • 举报
回复
select sum(字段名) as getsum from tablename where 日期>'2003-6-1'
你在DELPHI中是怎么写的,直接这样可不行,要注意单引号

第二个你可以在字段值改变的时候写代码
ruihuahan 2003-06-04
  • 打赏
  • 举报
回复
UP
myling 2003-06-04
  • 打赏
  • 举报
回复
1. 日期型要加引号的!

2.
procedure TForm3.DBGrid1ColExit(Sender: TObject);
begin

……

if DBGrid1.SelectedField.Name='Emp_ID' then
DataSet1.FieldByName('Emp_Name').value :=Copy(DBGrid1.SelectedField.Value,1,3);

……

end;

ngyxh 2003-06-04
  • 打赏
  • 举报
回复
up
tomyang 2003-06-04
  • 打赏
  • 举报
回复
第二个问题可以考虑用 “计算字段”
tomyang 2003-06-04
  • 打赏
  • 举报
回复
select sum(字段名) as getsum from tablename where 日期>'2003-6-1'
可能和你用的数据库有关,数据库的日期类型可能不支持'2003-6-1'
ngyxh 2003-06-04
  • 打赏
  • 举报
回复
哪位大哥能做好一个示范程序啊.就像上面说的问题一样.麻烦给我发过来.分另外算.

ngyxh@yeah.net

ngyxh 2003-06-04
  • 打赏
  • 举报
回复
"日期"的字段类型是data型的,改成select sum(字段名) as getsum from tablename where 日期>'2003-6-1'以后还是出现:"Type mismatch in expression."我用的BDE.
ngyxh 2003-06-04
  • 打赏
  • 举报
回复
"日期"的字段类型是data型的,改成select sum(字段名) as getsum from tablename where 日期>'2003-6-1'以后还是出现:"Type mismatch in expression."我用的BDE.
hansion3406 2003-06-04
  • 打赏
  • 举报
回复
单引号...
如果觉得单引号麻烦的话就用PARAM
firetoucher 2003-06-04
  • 打赏
  • 举报
回复
如果你用的是ACCESS,在参数前后不是加引号,而是#
ngyxh 2003-06-04
  • 打赏
  • 举报
回复
我用的BDE的数据库
jianke5555 2003-06-04
  • 打赏
  • 举报
回复
对了,在这个事件中:
procedure TForm3.DBGrid1ColExit(Sender: TObject);
begin

end;
jianke5555 2003-06-04
  • 打赏
  • 举报
回复
1。前面都是对的。
2。
if DBGrid1.SelectedField.Name='Emp_ID' then
DataSet1.FieldByName('Emp_Name').value :=Copy(DBGrid1.SelectedField.Value,1,3);
lovelymelon 2003-06-04
  • 打赏
  • 举报
回复
你日期的数据类型是datetiem型吗?
如果是,用参数吧
select sum(字段名) as getsum from tablename where 日期>:s1;
adoquery1.Parameters.ParamByName('s1').Value:=strtodate('2001-6-1');
ngyxh 2003-06-04
  • 打赏
  • 举报
回复
为什么改成select sum(字段名) as getsum from tablename where 日期>'2003-6-1'以后还是出现:"Type mismatch in expression."啊
linzhisong 2003-06-04
  • 打赏
  • 举报
回复
日期要加引号

2。
procedure datachang(sender:Tfield);
begin
sender.dataset.edit;
sender.dataset.fields[1].asstring:=copy(sender.dataset.fields[0].asstring,0,3);
end;
数据集打开后:
dataset.fields[0].onchang:=datachang;
haoqingqlm 2003-06-04
  • 打赏
  • 举报
回复
或者使用参数
ado的
parameters.parambyname('mydate').value:=strotdate('2003-6-1');
ziqing 2003-06-04
  • 打赏
  • 举报
回复
你类型错误!select sum(字段名) as getsum from tablename where 日期>‘2003-6-1 ’
转化成字符相加就是了
我不要昵称 2003-06-04
  • 打赏
  • 举报
回复
严重同意 firetoucher
加载更多回复(2)

5,388

社区成员

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

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