HY,
我在Visual Studio 2015项目中使用Access数据库连接。不幸的是,如果使用该功能,我的Windows窗体在调试模式下不再正确显示。如果我不使用数据库连接一切正常 - 我认为我的连接有任何错误(字符串)?
Imports System.Data.OleDb
Module Datenbank
Private Const Provider As String = "Provider=Microsoft.ACE.OLEDB.12.0;"
Public Sub InitDbParameter(ByRef Con As OleDbConnection, ByRef Cmd As OleDbCommand)
Con.ConnectionString = Provider & "Data Source =" & Db
Cmd.Connection = Con
End Sub
Public Sub FillDGVMitarbeiter(ByRef DGV As DataGridView)
Dim Con As New OleDbConnection
Dim Cmd As New OleDbCommand
Dim Reader As OleDbDataReader
Dim i As Integer
Dim ID As String
InitDbParameter(Con, Cmd)
Con.Open()
Cmd.CommandText = "SELECT * FROM Mitarbeiter WHERE gelöscht= false;"
Try
Reader = Cmd.ExecuteReader()
DGV.RowCount = 0
Do While Reader.Read = vbTrue
i = DGV.RowCount
With DGV
.RowCount = i + 1
.Item("MitarbeiterID", i).Value = Reader("ID").ToString
.Item("MAVorname", i).Value = Reader("Vorname").ToString
.Item("MANachname", i).Value = Reader("Nachname").ToString
.Item("MaKürzel", i).Value = Reader("MA_Kürzel").ToString
.Item("MaEintrittsdatum", i).Value = Mid(Reader("Eintrittsdatum").ToString, 1, 10)
.Item("MaAustrittsdatum", i).Value = Mid(Reader("Austrittsdatum").ToString, 1, 10)
End With
Loop
Reader.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Con.Close()
End Sub