I want a DataGridView to obtain records from a query resided in an Access database.
The program run without error. The header name of the fields are displayed but not the records.
//////////////////////////////////////////////////////////////////////////////////
MS Access query Name: Q_SHOW_ALL_UNITS_AND_ITS_STATUS
SELECT DISTINCTROW Unit.Property_Name, Unit.Unit_Number, Unit.Bedroom, Unit.Rental_Cost, Unit.Security_Deposit, Unit.Bathroom, Unit.Square_Feet, Unit.Status, Tenant.Date_Lease_Expired, Tenant.Late_On_Payment, Tenant.Days_Delinquent
FROM Unit LEFT JOIN Tenant ON (Unit.Unit_Number = Tenant.Unit_Number) AND (Unit.Property_Name = Tenant.Property_Name)
ORDER BY Unit.Property_Name, Unit.Unit_Number, Unit.Bedroom, Unit.Rental_Cost;
//////////////////////////////////////////////////////////////////////////////////
dataGridView Name: dataGridView1
right click dataGridView1 --> Properties --> DataSource = qSHOWALLUNITSANDITSSTATUSBindingSource
qSHOWALLUNITSANDITSSTATUSBindingSource --> Q_SHOW_ALL_UNITS_AND_ITS_STATUS
//////////////////////////////////////////////////////////////////////////////////
The program run without error. The header name of the fields are displayed but not the records.
//////////////////////////////////////////////////////////////////////////////////
MS Access query Name: Q_SHOW_ALL_UNITS_AND_ITS_STATUS
SELECT DISTINCTROW Unit.Property_Name, Unit.Unit_Number, Unit.Bedroom, Unit.Rental_Cost, Unit.Security_Deposit, Unit.Bathroom, Unit.Square_Feet, Unit.Status, Tenant.Date_Lease_Expired, Tenant.Late_On_Payment, Tenant.Days_Delinquent
FROM Unit LEFT JOIN Tenant ON (Unit.Unit_Number = Tenant.Unit_Number) AND (Unit.Property_Name = Tenant.Property_Name)
ORDER BY Unit.Property_Name, Unit.Unit_Number, Unit.Bedroom, Unit.Rental_Cost;
//////////////////////////////////////////////////////////////////////////////////
dataGridView Name: dataGridView1
right click dataGridView1 --> Properties --> DataSource = qSHOWALLUNITSANDITSSTATUSBindingSource
qSHOWALLUNITSANDITSSTATUSBindingSource --> Q_SHOW_ALL_UNITS_AND_ITS_STATUS
//////////////////////////////////////////////////////////////////////////////////
Form1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Data_Grid_View_And_Access
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'aMS_2007DataSet.Q_SHOW_ALL_UNITS_AND_ITS_STATUS' table.
// You can move, or remove it, as needed.
this.q_SHOW_ALL_UNITS_AND_ITS_STATUSTableAdapter.Fill(this.aMS_2007DataSet.Q_SHOW_ALL_UNITS_AND_ITS_STATUS);
}
}
}
Form1.Designer.cs:
namespace Data_Grid_View_And_Access
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.aMS_2007DataSet = new Data_Grid_View_And_Access.AMS_2007DataSet();
this.qSHOWALLUNITSANDITSSTATUSBindingSource = new System.Windows.Forms.BindingSource(this.components);
this.q_SHOW_ALL_UNITS_AND_ITS_STATUSTableAdapter = new Data_Grid_View_And_Access.AMS_2007DataSetTableAdapters.Q_SHOW_ALL_UNITS_AND_ITS_STATUSTableAdapter();
this.propertyNameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.unitNumberDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.bedroomDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.rentalCostDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.securityDepositDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.bathroomDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.squareFeetDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.statusDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dateLeaseExpiredDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.lateOnPaymentDataGridViewCheckBoxColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.daysDelinquentDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.aMS_2007DataSet)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.qSHOWALLUNITSANDITSSTATUSBindingSource)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.propertyNameDataGridViewTextBoxColumn,
this.unitNumberDataGridViewTextBoxColumn,
this.bedroomDataGridViewTextBoxColumn,
this.rentalCostDataGridViewTextBoxColumn,
this.securityDepositDataGridViewTextBoxColumn,
this.bathroomDataGridViewTextBoxColumn,
this.squareFeetDataGridViewTextBoxColumn,
this.statusDataGridViewTextBoxColumn,
this.dateLeaseExpiredDataGridViewTextBoxColumn,
this.lateOnPaymentDataGridViewCheckBoxColumn,
this.daysDelinquentDataGridViewTextBoxColumn});
this.dataGridView1.DataSource = this.qSHOWALLUNITSANDITSSTATUSBindingSource;
this.dataGridView1.Location = new System.Drawing.Point(78, 88);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowHeadersWidth = 51;
this.dataGridView1.RowTemplate.Height = 24;
this.dataGridView1.Size = new System.Drawing.Size(665, 306);
this.dataGridView1.TabIndex = 0;
this.dataGridView1.DataSourceChanged += new System.EventHandler(this.Form1_Load);
//
// aMS_2007DataSet
//
this.aMS_2007DataSet.DataSetName = "AMS_2007DataSet";
this.aMS_2007DataSet.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
//
// qSHOWALLUNITSANDITSSTATUSBindingSource
//
this.qSHOWALLUNITSANDITSSTATUSBindingSource.DataMember = "Q_SHOW_ALL_UNITS_AND_ITS_STATUS";
this.qSHOWALLUNITSANDITSSTATUSBindingSource.DataSource = this.aMS_2007DataSet;
//
// q_SHOW_ALL_UNITS_AND_ITS_STATUSTableAdapter
//
this.q_SHOW_ALL_UNITS_AND_ITS_STATUSTableAdapter.ClearBeforeFill = true;
//
// propertyNameDataGridViewTextBoxColumn
//
this.propertyNameDataGridViewTextBoxColumn.DataPropertyName = "Property_Name";
this.propertyNameDataGridViewTextBoxColumn.HeaderText = "Property_Name";
this.propertyNameDataGridViewTextBoxColumn.MinimumWidth = 6;
this.propertyNameDataGridViewTextBoxColumn.Name = "propertyNameDataGridViewTextBoxColumn";
this.propertyNameDataGridViewTextBoxColumn.Width = 125;
//
// unitNumberDataGridViewTextBoxColumn
//
this.unitNumberDataGridViewTextBoxColumn.DataPropertyName = "Unit_Number";
this.unitNumberDataGridViewTextBoxColumn.HeaderText = "Unit_Number";
this.unitNumberDataGridViewTextBoxColumn.MinimumWidth = 6;
this.unitNumberDataGridViewTextBoxColumn.Name = "unitNumberDataGridViewTextBoxColumn";
this.unitNumberDataGridViewTextBoxColumn.Width = 125;
//
// bedroomDataGridViewTextBoxColumn
//
this.bedroomDataGridViewTextBoxColumn.DataPropertyName = "Bedroom";
this.bedroomDataGridViewTextBoxColumn.HeaderText = "Bedroom";
this.bedroomDataGridViewTextBoxColumn.MinimumWidth = 6;
this.bedroomDataGridViewTextBoxColumn.Name = "bedroomDataGridViewTextBoxColumn";
this.bedroomDataGridViewTextBoxColumn.Width = 125;
//
// rentalCostDataGridViewTextBoxColumn
//
this.rentalCostDataGridViewTextBoxColumn.DataPropertyName = "Rental_Cost";
this.rentalCostDataGridViewTextBoxColumn.HeaderText = "Rental_Cost";
this.rentalCostDataGridViewTextBoxColumn.MinimumWidth = 6;
this.rentalCostDataGridViewTextBoxColumn.Name = "rentalCostDataGridViewTextBoxColumn";
this.rentalCostDataGridViewTextBoxColumn.Width = 125;
//
// securityDepositDataGridViewTextBoxColumn
//
this.securityDepositDataGridViewTextBoxColumn.DataPropertyName = "Security_Deposit";
this.securityDepositDataGridViewTextBoxColumn.HeaderText = "Security_Deposit";
this.securityDepositDataGridViewTextBoxColumn.MinimumWidth = 6;
this.securityDepositDataGridViewTextBoxColumn.Name = "securityDepositDataGridViewTextBoxColumn";
this.securityDepositDataGridViewTextBoxColumn.Width = 125;
//
// bathroomDataGridViewTextBoxColumn
//
this.bathroomDataGridViewTextBoxColumn.DataPropertyName = "Bathroom";
this.bathroomDataGridViewTextBoxColumn.HeaderText = "Bathroom";
this.bathroomDataGridViewTextBoxColumn.MinimumWidth = 6;
this.bathroomDataGridViewTextBoxColumn.Name = "bathroomDataGridViewTextBoxColumn";
this.bathroomDataGridViewTextBoxColumn.Width = 125;
//
// squareFeetDataGridViewTextBoxColumn
//
this.squareFeetDataGridViewTextBoxColumn.DataPropertyName = "Square_Feet";
this.squareFeetDataGridViewTextBoxColumn.HeaderText = "Square_Feet";
this.squareFeetDataGridViewTextBoxColumn.MinimumWidth = 6;
this.squareFeetDataGridViewTextBoxColumn.Name = "squareFeetDataGridViewTextBoxColumn";
this.squareFeetDataGridViewTextBoxColumn.Width = 125;
//
// statusDataGridViewTextBoxColumn
//
this.statusDataGridViewTextBoxColumn.DataPropertyName = "Status";
this.statusDataGridViewTextBoxColumn.HeaderText = "Status";
this.statusDataGridViewTextBoxColumn.MinimumWidth = 6;
this.statusDataGridViewTextBoxColumn.Name = "statusDataGridViewTextBoxColumn";
this.statusDataGridViewTextBoxColumn.Width = 125;
//
// dateLeaseExpiredDataGridViewTextBoxColumn
//
this.dateLeaseExpiredDataGridViewTextBoxColumn.DataPropertyName = "Date_Lease_Expired";
this.dateLeaseExpiredDataGridViewTextBoxColumn.HeaderText = "Date_Lease_Expired";
this.dateLeaseExpiredDataGridViewTextBoxColumn.MinimumWidth = 6;
this.dateLeaseExpiredDataGridViewTextBoxColumn.Name = "dateLeaseExpiredDataGridViewTextBoxColumn";
this.dateLeaseExpiredDataGridViewTextBoxColumn.Width = 125;
//
// lateOnPaymentDataGridViewCheckBoxColumn
//
this.lateOnPaymentDataGridViewCheckBoxColumn.DataPropertyName = "Late_On_Payment";
this.lateOnPaymentDataGridViewCheckBoxColumn.HeaderText = "Late_On_Payment";
this.lateOnPaymentDataGridViewCheckBoxColumn.MinimumWidth = 6;
this.lateOnPaymentDataGridViewCheckBoxColumn.Name = "lateOnPaymentDataGridViewCheckBoxColumn";
this.lateOnPaymentDataGridViewCheckBoxColumn.Width = 125;
//
// daysDelinquentDataGridViewTextBoxColumn
//
this.daysDelinquentDataGridViewTextBoxColumn.DataPropertyName = "Days_Delinquent";
this.daysDelinquentDataGridViewTextBoxColumn.HeaderText = "Days_Delinquent";
this.daysDelinquentDataGridViewTextBoxColumn.MinimumWidth = 6;
this.daysDelinquentDataGridViewTextBoxColumn.Name = "daysDelinquentDataGridViewTextBoxColumn";
this.daysDelinquentDataGridViewTextBoxColumn.Width = 125;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.dataGridView1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.aMS_2007DataSet)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.qSHOWALLUNITSANDITSSTATUSBindingSource)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dataGridView1;
private AMS_2007DataSet aMS_2007DataSet;
private System.Windows.Forms.BindingSource qSHOWALLUNITSANDITSSTATUSBindingSource;
private AMS_2007DataSetTableAdapters.Q_SHOW_ALL_UNITS_AND_ITS_STATUSTableAdapter q_SHOW_ALL_UNITS_AND_ITS_STATUSTableAdapter;
private System.Windows.Forms.DataGridViewTextBoxColumn propertyNameDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn unitNumberDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn bedroomDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn rentalCostDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn securityDepositDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn bathroomDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn squareFeetDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn statusDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn dateLeaseExpiredDataGridViewTextBoxColumn;
private System.Windows.Forms.DataGridViewCheckBoxColumn lateOnPaymentDataGridViewCheckBoxColumn;
private System.Windows.Forms.DataGridViewTextBoxColumn daysDelinquentDataGridViewTextBoxColumn;
}
}
program.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Data_Grid_View_And_Access
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="Data_Grid_View_And_Access.Properties.Settings.AMS_2007ConnectionString"
connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\AMS_2007.accdb"
providerName="System.Data.OleDb" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>