SQL.Add('select * from login where 用户名=' + QuotedStr(Edit1.Text) + ' and 用户密码=' + QuotedStr(Edit2.Text) ' and 用户权限=' + QuotedStr(comboBox1.Text)); 上面的语句有问题吗。。应该怎么改
var sql: string; begin sql:= format('select * from login where 用户名=''%s'' and 用户密码=''%s'' and 用户权限=''%s''',[edit1.text,edit2.text,combobox1.text]); ... ... SQL.Add(sql); ... ... end;
问xixuemao(一点技术含量都没有) 为什么要写成这样的格式呢?
同意楼上的,用Format看起来清晰多了
SQL.Add('select * from login where 用户名=''' + QuotedStr(Edit1.Text) + ''' and 用户密码=''' + QuotedStr(Edit2.Text) ''' and 用户权限=''' + QuotedStr(comboBox1.Text))+''''; 我想,字符串两边是要加'的
要么采用参数替代变量 要么 ... 用户名="'+ QuotedStr(Edit1.Text) + '" and ...
哦,对哦,还少了个+ SQL.Add('select * from login where 用户名=''' + QuotedStr(Edit1.Text) + ''' and 用户密码=''' + QuotedStr(Edit2.Text) +''' and 用户权限=''' + QuotedStr(comboBox1.Text))+'''';
sql: string;
begin
sql:= format('select * from login where 用户名=''%s'' and 用户密码=''%s'' and 用户权限=''%s''',[edit1.text,edit2.text,combobox1.text]);
...
...
SQL.Add(sql);
...
...
end;
为什么要写成这样的格式呢?
SQL.Add('select * from login where 用户名=''' + QuotedStr(Edit1.Text) + ''' and 用户密码=''' + QuotedStr(Edit2.Text) ''' and 用户权限=''' + QuotedStr(comboBox1.Text))+'''';
我想,字符串两边是要加'的
要么
... 用户名="'+ QuotedStr(Edit1.Text) + '" and ...
为什么要写成这样的格式呢?
=============
呵呵,个人习惯而已!不会因为'号出错!
SQL.Add('select * from login where 用户名=''' + QuotedStr(Edit1.Text) + ''' and 用户密码=''' + QuotedStr(Edit2.Text) +''' and 用户权限=''' + QuotedStr(comboBox1.Text))+'''';