首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

新添加数据 往数据库中

2012-04-01 
新添加数据求助往数据库中function TForm2.addqury(Query:TADOQuery): booleanvar sSQL,str0: stringbeg

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

热点排行