| |

VerySource

 Forgot password?
 Register
Search
View: 1050|Reply: 4

Database issues?

[Copy link]

4

Threads

15

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-3-20 17:00:01
| Show all posts |Read mode
When I created the form, I opened the tables Query1, Query2, Query3
And the query in Query1 is as follows:
   select student.s_no, s_name, s_sex, s_age, s_address, s_nation, s_college, s_subject, s_class, s_grade, s_phone, s_picture, building.building_no, house.house_no, bed_no

  from building, house, bed, student

where building.building_no = house.building_no And house.house_no = bed.house_no And bed.s_no = student.s_no

// Query1's AfterScroll event is as follows:
// But there is an error when running, I give the error line in the program

procedure TAdmin_Operation_Form_AlterStudent.Query1AfterScroll (DataSet: TDataSet);
var
  MyJpeg: TJpegImage;
  MyStm: TMemoryStream;
begin
  query2.Close;
  query2.SQL.Clear;
  query2.SQL.Add ('select * from house where building_no =: para_building_no');
  query2.SQL.Add ('AND house_no =: para_house_no');
  query2.ParamByName ('para_building_no'). AsString: = query1.fieldByName ('building.building_no'). AsString;

// The above line is wrong, saying that the 'building.building_no' field does not exist.
  query2.ParamByName ('para_house_no'). AsString: = query1.fieldByName ('house.house_no'). AsString;
  query2.Open;
  query3.Close;
  query3.SQL.Clear;
  query3.SQL.Add ('select * from bed where bed_no =: para_bed_no');
  query3.ParamByName ('para_bed_no'). AsString: = query1.fieldByName ('bed_no'). AsString;
  query3.Open;
  query4.Close;
  query4.SQL.Clear;
  query4.SQL.Add ('select * from student where s_no =: para_s_no');
  query4.ParamByName ('para_s_no'). AsString: = query1.fieldByName ('bed_no'). AsString;
  query4.Open;
  if not query4.FieldByName ('s_picture'). IsNull then
  begin
    try
      MyJpeg: = TJpegImage.Create;
      MyStm: = TMemoryStream.Create;
      MyStm.Clear;
      query4.Edit;
      TBlobField (query4.FieldByName ('s_picture')). SaveToStream (MyStm);
      MyStm.Position: = 0;
      MyJpeg.LoadFromStream (MyStm);
      Image1.Picture.BitMap.Assign (MyJpeg);
    finally
      MyJpeg.Free;
      MyStm.Free;
    end;
  end
end;


Which hero would you like to help and see where I am wrong? ? ?
Thank you all! !!
Reply

Use magic Report

0

Threads

53

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-6-28 14:30:01
| Show all posts
Here you use building_no directly, do not add a reference, or give it an alias
Reply

Use magic Report

4

Threads

15

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-7-5 16:30:02
| Show all posts
Thank you! ! !
Can you tell me why? ?
Why is it wrong to add the table name here?
I made an error without adding the table name in another window!
Reply

Use magic Report

0

Threads

13

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-7-5 21:00:01
| Show all posts
1: select a. field 1, b. field 2 from table1 a, table2 b where //.. If from is multiple tables, then each field in the front must be prefixed, either table name or table name Alias

2: this sentence
query2.ParamByName('para_building_no').AsString := query1.fieldByName('building.building_no').AsString;
//query1 is turned on, you either write select building.building_no as [building] in the sentence executed by query1 so you can put
query2.ParamByName('para_building_no').AsString := query1.fieldByName('building.building_no').AsString;
Change to
query2.ParamByName('para_building_no').AsString := query1.fieldByName('building_no').AsString;

Your understanding is not clear enough, and the operation of the database is not clear. After the query is executed, it is a separate table, which has nothing to do with other tables. If you use the alias of other tables, you can’t access it.
Reply

Use magic Report

4

Threads

15

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-7-6 19:45:01
| Show all posts
Thank you very muchyourapy! ! !
You have solved my doubts! ! ! Know what is going on, thank you again! ! !
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list