1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| ' Please be sure of the database path, I suppose it will be in the same folder where the application exe file is in (usually should be in 'YourProjectPath\bin\debug')
Dim MyConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + Application.StartupPath + "\applicationhebergement.accdb"
' Generating the DataSet and the DataAdapter
Dim ds As New DataSet()
' All 'Customers' table's columns could fit in one page
Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM etudiant", MyConnectionString)
' All 'Customers2' table's columns could fit in two page
'Dim da As New OleDbDataAdapter("SELECT * FROM Customers2", MyConnectionString)
Try
da.Fill(ds, "dt")
Catch ex As Exception
MessageBox.Show("Operation failed: " + ex.ToString(), Application.ProductName + " - Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
Return
End Try
' Setting the style of the DataGridView control
myDataGridView.ColumnHeadersDefaultCellStyle.Font = New Font("Tahoma", 9, FontStyle.Bold, GraphicsUnit.Point)
myDataGridView.ColumnHeadersDefaultCellStyle.BackColor = SystemColors.ControlDark
myDataGridView.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.[Single]
myDataGridView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
myDataGridView.DefaultCellStyle.Font = New Font("Tahoma", 8, FontStyle.Regular, GraphicsUnit.Point)
myDataGridView.DefaultCellStyle.BackColor = Color.Empty
myDataGridView.AlternatingRowsDefaultCellStyle.BackColor = SystemColors.ControlLight
myDataGridView.CellBorderStyle = DataGridViewCellBorderStyle.[Single]
myDataGridView.GridColor = SystemColors.ControlDarkDark
' Binding the DataGridViewControl to the DataSet generated above
myDataGridView.DataSource = ds
myDataGridView.DataMember = "dt"
' Changing the last column alignment to be in the Right alignment
myDataGridView.Columns(myDataGridView.Columns.Count - 1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
' Adjusting each column to be fit as the content of all its cells, including the header cell
myDataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
'MyDataGridView.Columns[0].Visible = false;
myDataGridView.Show() |
Partager