新添加数据 求助往数据库中
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没有初值
求助怎么处理
[解决办法]
QuotedStr是什么函数?
if comboBox1.text='男' then
str0:='1'
else
str0:='0';
[解决办法]
sSQL := 'insert into person(XH,SNAME,SEX,MARKS) Values(' + QuotedStr(Edit1.Text) + ',' + QuotedStr(Edit2.Text) + ','+ Str0 + ',' + QuotedStr(Edit3.Text) + ')';
Str0是變量,也要用“+”連接起來。
[解决办法]
设置comboBox1内容順序: 男,女(男排第1位)
function TForm2.addqury(Query:TADOQuery): boolean;
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;