procedure TTIMuLuRu.LR_Button2Click(Sender: TObject); type SZ=array[1..5]of string; var temp,x,i,y:integer; temp1,temp2:string; SZx:SZ; begin y:=0; i:=1; SZx[1]:=''; if TM_Edit2.Text='' then ShowMessage('题目不能为空') else if NY_ComboBox2.Text='' then ShowMessage('难易度不能为空') else if ZJ_ComboBox2.Text='' then ShowMessage('所在章节不能为空') else if Kong_ComboBox.Text='' then ShowMessage('空数不能为空') else begin temp:=StrToInt(Kong_ComboBox.Text); SZx[1]:=Kong_Edit1.Text; SZx[2]:=Kong_Edit2.Text; SZx[3]:=Kong_Edit3.Text; SZx[4]:=Kong_Edit4.Text; SZx[5]:=Kong_Edit5.Text; for x:=1 To temp do begin i:=x; if SZx[i]='' then break; end; end; if SZx[i]='' then ShowMessage('您少输入了应填空的答案') else begin temp1:=TM_Edit2.Text; ADOQuery2.Close; ADOQuery2.SQL.Clear; ADOQuery2.SQL.Add('SELECT TM FROM TianKong'); ADOQuery2.Open; While not ADOQuery2.Eof do begin temp2:=ADOQuery2.FieldValues['TM']; if temp1=temp2 then begin y:=1; break; end; ADOQuery2.Next; end; if y=0 then begin ADOQuery1.Close; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add('Select TypeID From Type Where TypeName=''填空题'''); ADOQuery1.Open; temp:=ADOQuery1.FieldValues['TypeID']; ADOQuery1.Close; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add('INSERT INTO TianKong(TypeID,TM,K1,K2,K3,K4,K5,YTS,NY,CZ) VALUES(:temp,:TM,:K1,:K2,:K3,:K4,:K5,:YTS,:NY,:CZ)'); ADOQuery1.Parameters.ParamByName('temp').Value:=temp; ADOQuery1.Parameters.ParamByName('TM').Value:=TM_Edit2.Text; ADOQuery1.Parameters.ParamByName('K1').Value:=Kong_Edit1.Text; ADOQuery1.Parameters.ParamByName('K2').Value:=Kong_Edit2.Text; ADOQuery1.Parameters.ParamByName('K3').Value:=Kong_Edit3.Text; ADOQuery1.Parameters.ParamByName('K4').Value:=Kong_Edit4.Text; ADOQuery1.Parameters.ParamByName('K5').Value:=Kong_Edit5.Text; ADOQuery1.Parameters.ParamByName('YTS').Value:=StrToInt(Kong_ComboBox.Text); ADOQuery2.Close; ADOQuery2.SQL.Clear; ADOQuery2.SQL.Add('Select BH From NYD Where NYD=:NY'); ADOQuery2.Parameters.ParamByName('NY').Value:=NY_ComboBox2.Text; ADOQuery2.Open; temp:=ADOQuery2.FieldValues['BH']; ADOQuery1.Parameters.ParamByName('NY').Value:=temp; ADOQuery1.Parameters.ParamByName('CZ').Value:=ZJ_ComboBox2.Text; ADOQuery1.ExecSQL; !!!!!!ADOQuery1.Close; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add('Select 1 From TianKong'); ADOQuery1.Open; TH_Edit2.Text:=IntToStr(ADOQuery1.RecordCount+1); TM_Edit2.Clear; Kong_Edit1.Clear; Kong_Edit2.Clear; Kong_Edit3.Clear; Kong_Edit4.Clear; Kong_Edit5.Clear; end else showmessage('此题已经存在!'); end; end; 加感叹号的就是运行时报错停的地方
if y=0 then begin ADOQuery1.Close; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add('Select TypeID From Type Where TypeName=''填空题'''); ADOQuery1.Open; temp:=ADOQuery1.FieldValues['TypeID']; ADOQuery2.Close; ADOQuery2.SQL.Clear; ADOQuery2.SQL.Add('Select BH From NYD Where NYD=:NY'); ADOQuery2.Parameters.ParamByName('NY').Value:=NY_ComboBox2.Text; ADOQuery2.Open; temp1:=ADOQuery2.FieldValues['BH'];
如果是在运行期出错,可能是参数值与类型不匹配。
type
SZ=array[1..5]of string;
var
temp,x,i,y:integer;
temp1,temp2:string;
SZx:SZ;
begin
y:=0;
i:=1;
SZx[1]:='';
if TM_Edit2.Text='' then ShowMessage('题目不能为空')
else if NY_ComboBox2.Text='' then ShowMessage('难易度不能为空')
else if ZJ_ComboBox2.Text='' then ShowMessage('所在章节不能为空')
else if Kong_ComboBox.Text='' then ShowMessage('空数不能为空')
else begin
temp:=StrToInt(Kong_ComboBox.Text);
SZx[1]:=Kong_Edit1.Text;
SZx[2]:=Kong_Edit2.Text;
SZx[3]:=Kong_Edit3.Text;
SZx[4]:=Kong_Edit4.Text;
SZx[5]:=Kong_Edit5.Text;
for x:=1 To temp do
begin
i:=x;
if SZx[i]='' then break;
end;
end;
if SZx[i]='' then ShowMessage('您少输入了应填空的答案')
else begin
temp1:=TM_Edit2.Text;
ADOQuery2.Close;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Add('SELECT TM FROM TianKong');
ADOQuery2.Open;
While not ADOQuery2.Eof do
begin
temp2:=ADOQuery2.FieldValues['TM'];
if temp1=temp2 then begin
y:=1;
break;
end;
ADOQuery2.Next;
end;
if y=0 then begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select TypeID From Type Where TypeName=''填空题''');
ADOQuery1.Open;
temp:=ADOQuery1.FieldValues['TypeID'];
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('INSERT INTO TianKong(TypeID,TM,K1,K2,K3,K4,K5,YTS,NY,CZ) VALUES(:temp,:TM,:K1,:K2,:K3,:K4,:K5,:YTS,:NY,:CZ)');
ADOQuery1.Parameters.ParamByName('temp').Value:=temp;
ADOQuery1.Parameters.ParamByName('TM').Value:=TM_Edit2.Text;
ADOQuery1.Parameters.ParamByName('K1').Value:=Kong_Edit1.Text;
ADOQuery1.Parameters.ParamByName('K2').Value:=Kong_Edit2.Text;
ADOQuery1.Parameters.ParamByName('K3').Value:=Kong_Edit3.Text;
ADOQuery1.Parameters.ParamByName('K4').Value:=Kong_Edit4.Text;
ADOQuery1.Parameters.ParamByName('K5').Value:=Kong_Edit5.Text;
ADOQuery1.Parameters.ParamByName('YTS').Value:=StrToInt(Kong_ComboBox.Text);
ADOQuery2.Close;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Add('Select BH From NYD Where NYD=:NY');
ADOQuery2.Parameters.ParamByName('NY').Value:=NY_ComboBox2.Text;
ADOQuery2.Open;
temp:=ADOQuery2.FieldValues['BH'];
ADOQuery1.Parameters.ParamByName('NY').Value:=temp;
ADOQuery1.Parameters.ParamByName('CZ').Value:=ZJ_ComboBox2.Text;
ADOQuery1.ExecSQL;
!!!!!!ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select 1 From TianKong');
ADOQuery1.Open;
TH_Edit2.Text:=IntToStr(ADOQuery1.RecordCount+1);
TM_Edit2.Clear;
Kong_Edit1.Clear;
Kong_Edit2.Clear;
Kong_Edit3.Clear;
Kong_Edit4.Clear;
Kong_Edit5.Clear;
end
else showmessage('此题已经存在!');
end;
end;
加感叹号的就是运行时报错停的地方
ADOQuery1.Parameters.ParamByName('NY').Value:=temp;
ADOQuery1.Parameters.ParamByName('CZ').Value:=ZJ_ComboBox2.Text;
ADOQuery1.ExecSQL;
!!!!!!ADOQuery1.Close;--->>>>>>>>>>>>>..
temp:=ADOQuery2.FieldByName('BH').AsString;
ADOQuery1.Parameters.ParamByName('NY').Value:=temp;
ADOQuery1.Parameters.ParamByName('CZ').Value:=ZJ_ComboBox2.Text;
ADOQuery1.ExecSQL;
从程序上看
YTS:integer
NY:String
CZ:String但实际上表格的数据类型是什么你要看清楚了。
TypeID 数字
TM 文本
K1 文本
K2 文本
K3 文本
K4 文本
YTS 数字
NY 数字
CZ 文本
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>表nyd
BH 自动编号
NYD 文本
ADOQuery1.Parameters.ParamByName('TM').Value:=TM_Edit2.Text;
ADOQuery1.Parameters.ParamByName('K1').Value:=Kong_Edit1.Text;
ADOQuery1.Parameters.ParamByName('K2').Value:=Kong_Edit2.Text;
ADOQuery1.Parameters.ParamByName('K3').Value:=Kong_Edit3.Text;
ADOQuery1.Parameters.ParamByName('K4').Value:=Kong_Edit4.Text;
ADOQuery1.Parameters.ParamByName('K5').Value:=Kong_Edit5.Text;
ADOQuery1.Parameters.ParamByName('YTS').Value:=StrToInt(Kong_ComboBox.Text);
>>>>>>>>>>>>>>>>>>>>>>>>>>>
ADOQuery1.Parameters.ParamByName('temp').Value:=temp;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select TypeID From Type Where TypeName=''填空题''');
ADOQuery1.Open;
temp:=ADOQuery1.FieldValues['TypeID']; ADOQuery2.Close;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Add('Select BH From NYD Where NYD=:NY');
ADOQuery2.Parameters.ParamByName('NY').Value:=NY_ComboBox2.Text;
ADOQuery2.Open;
temp1:=ADOQuery2.FieldValues['BH'];
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('INSERT INTO TianKong(TypeID,TM,K1,K2,K3,K4,K5,YTS,NY,CZ)
ADOQuery1.SQL.Add(format('VALUES(%d,''%s'',''%s'',''%s'',''%s'',''%s'',''%s'',%d,%d,''%s'')',[temp,TM_Edit2.Text,
Kong_Edit1.Text,
Kong_Edit2.Text,
Kong_Edit3.Text,
Kong_Edit4.Text,
Kong_Edit5.Text,
StrToInt(Kong_ComboBox.Text),
temp1,
ZJ_ComboBox2.Text])); ADOQuery1.ExecSQL;
!!!!!!ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select 1 From TianKong');
ADOQuery1.Open;
TH_Edit2.Text:=IntToStr(ADOQuery1.RecordCount+1);
TM_Edit2.Clear;
Kong_Edit1.Clear;
Kong_Edit2.Clear;
Kong_Edit3.Clear;
Kong_Edit4.Clear;
Kong_Edit5.Clear;
end
else showmessage('此题已经存在!');
end;
end;