function TForm2.addqury(Query:TADOQuery): boolean;
var sSQL,str0: string;
begin
if comboBox1.text='男' then
str0:=QuotedStr('1')
else
str0:=QuotedStr('0');
Query.SQL.clear;
sSQL := 'insert into person(XH,SNAME,SEX,MARKS) Values(' + QuotedStr(Edit1.Text) + ',' + QuotedStr(Edit2.Text) + ',Str0,' + QuotedStr(Edit3.Text) + ')';
Query.SQL.Text := sSQL;
Query.ExecSQL;
end;运行说 str0没有初值
求助怎么处理
var sSQL,str0: string;
begin
if comboBox1.text='男' then
str0:=QuotedStr('1')
else
str0:=QuotedStr('0');
Query.SQL.clear;
sSQL := 'insert into person(XH,SNAME,SEX,MARKS) Values(' + QuotedStr(Edit1.Text) + ',' + QuotedStr(Edit2.Text) + ',Str0,' + QuotedStr(Edit3.Text) + ')';
Query.SQL.Text := sSQL;
Query.ExecSQL;
end;运行说 str0没有初值
求助怎么处理
if comboBox1.text='男' then
str0:='1'
else
str0:='0';
str0:=QuotedStr('0');
就是错误的,sql里的bool型变量不要引号
Str0是變量,也要用“+”連接起來。
begin
if comboBox1.ItemIndex<>-1 then
begin
Query.SQL.clear;
sSQL := 'insert into person(XH,SNAME,SEX,MARKS) Values(' + QuotedStr(Edit1.Text) + ',' + QuotedStr(Edit2.Text) + ','+IntTostr(comboBox1.ItemIndex)+',' + QuotedStr(Edit3.Text) + ')';
Query.SQL.Text := sSQL;
Query.ExecSQL;
end;
end;