请教,query的问题?

qhxhit 2005-04-11 03:27:58
Query:=TQuery.create(nil);
Query.DatabaseName:=DBname;
Query.SQL.Add('select*from Operator where UserName=:UserName and userpwd:=userpwd');

Query.ParamByName('UserName').AsString:=cmbusername.text;
Query.ParamByName('userPwd').AsString:=edtpassword.text;
Query.Open;
if Query.RecordCount=0then
begin
MessageDlg('请输入正确的用户名和密码',mtError,[mbok],0);
exit;
end ;
其中UserName和userpwd是Operator表的字段名。
现在我对Query.SQL.Add、Query.ParamByName('UserName')表达的意思不知道。
Query.SQL.Add返回一个整数,ParamByName('UserName')返回一个TParam,不知是什么东东
Query.RecordCount表达的是什么意思?
谢谢大侠指教!
...全文
102 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
qhxhit 2005-04-13
  • 打赏
  • 举报
回复
我已经解决了。谢谢大家的支持!
qhxhit 2005-04-11
  • 打赏
  • 举报
回复
能不能提供源代码,实现查询表中的字段与输入的名称一致。
qhxhit 2005-04-11
  • 打赏
  • 举报
回复
像这方面的内容在d帮助中我没有找到,可不可以介绍下
aus 2005-04-11
  • 打赏
  • 举报
回复
建议多看D的帮助
qhxhit 2005-04-11
  • 打赏
  • 举报
回复
rouqing(*冰雨&双子座奇缘*) 说得和我得意思差不多,实际是不是可以用cmbusername.text的string直接代替sql语句中的Username?
我想从operator表中查找到username 是cmbusername.text,密码是edtpassword.text,的用户
这样写行不行?编译通过,但运行说Query.ParamByName('UserName')的Username找不到!
我在Asess数据库中建立了operator表,且有Username字段名,见到了cmbusername.text中有建好的用户名。说明已经连接到数据库了。不知什么原因造成上面的错误!
hellolongbin 2005-04-11
  • 打赏
  • 举报
回复
Query.SQL.Add指的是添加sql语句,ParamByName('UserName')指的记录集中username字段的值,后面一遍还有.asstring等属性
Query.RecordCount指的是你的SQL语句检索出来的记录集的条数
hellolongbin 2005-04-11
  • 打赏
  • 举报
回复
走错门了,贴错了,sorry
hellolongbin 2005-04-11
  • 打赏
  • 举报
回复
Delphi Object and Component Reference
MidStr function

---------------------------------
Returns the substring of a specified length that appears at a specified position in a string.

Unit

StrUtils

Category

string handling routines

Delphi syntax:

function MidStr(const AText: AnsiString; const AStart, ACount: Integer): AnsiString; overload;
function MidStr(const AText: WideString; const AStart, ACount: Integer): WideString; overload;

C++ syntax:

extern PACKAGE AnsiString __fastcall MidStr(const AnsiString AText, int AStart, int ACount);
extern PACKAGE WideString __fastcall MidStr(const WideString AText, int AStart, int ACount);

Description

MidStr returns a substring Count characters at AText[AStart].

If AStart is larger than the length of AText, MidStr returns an empty string.

If Count specifies more characters than are available, only the characters from AText[AStart] to the end of AText are returned.

Note: If AText is an AnsiString and the current locale uses multi-byte characters, MidStr may return more than ACount bytes. To return a specific number of bytes, use MidBStr.
纯冰糖 2005-04-11
  • 打赏
  • 举报
回复
'Select Name from usertable where name='okok'
UserName='okok'
是这个意思吧
Query.ParamByName('UserName').AsString:=cmbusername.text;
cmbusername.text:='okok';
qhxhit 2005-04-11
  • 打赏
  • 举报
回复
Query.SQL.Add 追加SQL语句,我明白了。
Query.ParamByName('UserName') //给SQL语句中的对应参数赋值,
是不是把sql语句中的UserName赋值?
lij3024 2005-04-11
  • 打赏
  • 举报
回复
同意楼上的
纯冰糖 2005-04-11
  • 打赏
  • 举报
回复
Query.Sql.Add('Select Name from usertable where name=:UserName');
Query.ParamByName('UserName') //给SQL语句中的对应参数赋值
Query.RecordCount //query的返回记录总数
gxgyj 2005-04-11
  • 打赏
  • 举报
回复
Query.SQL.Add //追加SQL语句
Query.ParamByName('UserName') //给SQL语句中的对应参数赋值
Query.RecordCount //query的返回记录总数

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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