简体   繁体   中英

C# MYSQL multiple table in datagridview

I'm trying to put two tables in one datagridview in my c# windows form application.

At the moment I have one table connected in there which works perfectly fine. The query that I have set for it is this:

select ID, PatientID from clinic_inventory_system.appointment;

The above the code just selects the ID column and Patientid column in the appointment table. clinic_inventory_system is the database name.

What I'm trying to do is grab the First Name column & Last Name column from the Patient table and join it up with the ID & PatientID column in the appointment table

This is how I'm trying to set it up and struggling to do so. Could somebody please help me?

Column Names in the datagridview

  • ID (Appointment table)
  • PatientID (Foreign Key - Appointment table)
  • First Name (Patient table)
  • Last Name (Patient table)

Also, when referencing the column names could they also include the database name as I've already done it in the query above that works.

it would be easier to help you if you provide more details. For instance whether you're using ADO.Net or Generics.

Assuming you're retrieving the data from your database and storing it in a DataTable, you could simply store all your required columns in a single table by changing your query to:

Select a.ID, a.PatientID, p.FirstName, pLastName FROM clinic_inventory_system.appointment AS a INNER JOIN patient AS p ON p.PatientID = a.PatientID;

I hope this helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM