C
Co
Hi All,
I'm trying to fill a datagridview from a database but I can't get it
to work.
This is my code:
Private Sub CheckForExistingRoute()
Dim sql As String = "SELECT * FROM Route WHERE bestand=" & CInt
(iD)
Dim strTable As String = "Route"
Dim da As New OleDb.OleDbDataAdapter(sql, conn)
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim i As Integer = 1
Dim ds As New DataSet
conn.Open()
cb.QuotePrefix = "["
cb.QuoteSuffix = "]"
Try
da.SelectCommand = New OleDb.OleDbCommand(sql, conn)
da.Fill(ds, strTable)
If ds.Tables.Count > 0 _
Then
Dim dgvRow As New DataGridViewRow
Dim dgvCell As DataGridViewCell
Dim dr As DataRow
For Each dr In ds.Tables(0).Rows
dgvCell = New DataGridViewTextBoxCell()
dgvCell.Value = i
dgvRow.Cells.Add(dgvCell)
i = i + 1
dgvCell = New DataGridViewImageCell
dgvRow.Cells.Add(dgvCell)
dgvCell = New DataGridViewComboBoxCell
dgvCell.Value = dr.Item("naam")
dgvRow.Cells.Add(dgvCell)
dgvCell = New DataGridViewComboBoxCell
dgvCell.Value = dr.Item("functie")
dgvRow.Cells.Add(dgvCell)
dgvCell = New DataGridViewTextBoxCell()
dgvCell.Value = dr.Item("datum")
dgvRow.Cells.Add(dgvCell)
dgvCell = New DataGridViewCheckBoxCell()
dgvCell.Value = True
dgvRow.Cells.Add(dgvCell)
Next
DataGridView1.Rows.Add(dgvRow)
End If
Catch oException As OleDbException
MessageBox.Show(oException.Message)
Catch oException As Exception
MessageBox.Show(oException.Message)
End Try
conn.Close()
End Sub
Regards
Marco
I'm trying to fill a datagridview from a database but I can't get it
to work.
This is my code:
Private Sub CheckForExistingRoute()
Dim sql As String = "SELECT * FROM Route WHERE bestand=" & CInt
(iD)
Dim strTable As String = "Route"
Dim da As New OleDb.OleDbDataAdapter(sql, conn)
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim i As Integer = 1
Dim ds As New DataSet
conn.Open()
cb.QuotePrefix = "["
cb.QuoteSuffix = "]"
Try
da.SelectCommand = New OleDb.OleDbCommand(sql, conn)
da.Fill(ds, strTable)
If ds.Tables.Count > 0 _
Then
Dim dgvRow As New DataGridViewRow
Dim dgvCell As DataGridViewCell
Dim dr As DataRow
For Each dr In ds.Tables(0).Rows
dgvCell = New DataGridViewTextBoxCell()
dgvCell.Value = i
dgvRow.Cells.Add(dgvCell)
i = i + 1
dgvCell = New DataGridViewImageCell
dgvRow.Cells.Add(dgvCell)
dgvCell = New DataGridViewComboBoxCell
dgvCell.Value = dr.Item("naam")
dgvRow.Cells.Add(dgvCell)
dgvCell = New DataGridViewComboBoxCell
dgvCell.Value = dr.Item("functie")
dgvRow.Cells.Add(dgvCell)
dgvCell = New DataGridViewTextBoxCell()
dgvCell.Value = dr.Item("datum")
dgvRow.Cells.Add(dgvCell)
dgvCell = New DataGridViewCheckBoxCell()
dgvCell.Value = True
dgvRow.Cells.Add(dgvCell)
Next
DataGridView1.Rows.Add(dgvRow)
End If
Catch oException As OleDbException
MessageBox.Show(oException.Message)
Catch oException As Exception
MessageBox.Show(oException.Message)
End Try
conn.Close()
End Sub
Regards
Marco