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没有初值  
求助怎么处理

解决方案 »

  1.   

    QuotedStr是什么函数?
       
       if comboBox1.text='男' then
       str0:='1'
       else
       str0:='0';
     
      

  2.   

    如果QuotedStr是用来加引号的str0:=QuotedStr('1'):
    str0:=QuotedStr('0');
    就是错误的,sql里的bool型变量不要引号
     
      

  3.   

     sSQL := 'insert into person(XH,SNAME,SEX,MARKS) Values(' + QuotedStr(Edit1.Text) + ',' + QuotedStr(Edit2.Text) + ','+ Str0 + ',' + QuotedStr(Edit3.Text) + ')';
    Str0是變量,也要用“+”連接起來。
      

  4.   

    设置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;