检索数据的关闭方式?
SQLCmd.CommandText = "SELECT NAMA,SEKSYEN FROM STUDENT_INFORMATION WHERE MATRIC='" & TextBox1.Text & "'"
rd = SQLCmd.ExecuteReader
If rd.HasRows Then
rd.Read()
TextBox2.Text = rd.Item("NAMA").ToString
TextBox3.Text = rd.Item("SEKSYEN").ToString
rd.Close()
Else
TextBox2.Text = ""
TextBox3.Text = ""
MessageBox.Show("No Data!")
End If
我有一些。但是不知道在Delphi 7中是否有类似SqlDataReader
的方法
with ADOQuery1 do
begin
SQL.Clear;
SQL.Add('Select *');
SQL.Add('from REPORT');
SQL.Add('where CARD_ID = "' + card1.Text + '"');
if then
begin
Edit1.Text = rd.Item("SEKSYEN").AsString ;// wrong code trying to convert from above . not complete
ComboBox1.Text = rd.Item("SEKSYEN").AsString;// wrong code trying to convert from above . not complete
ComboBox2.Text = rd.Item("SEKSYEN").AsString ;// wrong code trying to convert from above . not complete
Edit2.Text = rd.Item("SEKSYEN").AsString ; // wrong code trying to convert from above . not complete
end;
你可以帮帮我吗?我被困了
答案 0 :(得分:1)
等效ExecuteReader
是Open
。 HasRows
为IsEmpty
,从一行读取各列的方法是通过Fields
使用FieldByName
集合:
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select *');
ADOQuery1.SQL.Add('from REPORT');
ADOQuery1.SQL.Add('where CARD_ID = "' + card1.Text + '"');
ADOQuery1.Open;
if not ADOQuery1.IsEmpty then
begin
Edit1.Text = ADOQuery1.FieldByName('SEKSYEN').AsString ;
ComboBox1.Text = ADOQuery1.FieldByName('SEKSYEN').AsString;
ComboBox2.Text = ADOQuery1.FieldByName('SEKSYEN').AsString ;
Edit2.Text = ADOQuery1.FieldByName('SEKSYEN').AsString;
end;