读书人

新添加数据 往数据库中

发布时间: 2012-04-01 17:23:46 作者: rapoo

新添加数据 求助往数据库中
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;

读书人网 >.NET

热点推荐