21-12-15, 12:16 PM
بسم الله الرحمن الرحيم
نشكر اخي hamada558 لمشاركة في حل المشكلة ولكن الى حتى الان بعد إضافة الكود لم نحل المشكلة وهنا الكود المستخدم كامل
نشكر اخي hamada558 لمشاركة في حل المشكلة ولكن الى حتى الان بعد إضافة الكود لم نحل المشكلة وهنا الكود المستخدم كامل
كود :
Public Function GetProvider(ByVal PathStr As String, Optional ByVal Password As String = "") As String
Dim ProviderStr As String
Select Case Path.GetExtension(PathStr)
Case ".mdb"
ProviderStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & PathStr & ";Jet OLEDB:Database Password=" & Password & ";"
Case ".accdb"
ProviderStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & PathStr & ";Persist Security Info=False;" & ";Jet OLEDB:Database Password=" & Password & ";"
Case ".xls"
ProviderStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" & PathStr & ";Extended Properties=Excel 8.0;"
Case ".xlsx"
ProviderStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & PathStr & ";Extended Properties=Excel 8.0;"
End Select
Return ProviderStr
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
ListBox1.ClearSelected()
Catch ex As Exception
End Try
Dim Password As String
Sniper:
Try
Dim OpenFileDialog1 As New OpenFileDialog
Dim DataSet1 As New DataSet
If Password = "" Then
Dim myStream As Stream = Nothing
OpenFileDialog1.Filter = "Files (*.mdb;*.accdb;*.xls;*.xlsx)|*.mdb;*.accdb;*.xls;*.xlsx"
OpenFileDialog1.Title = "Select a Cursor File"
OpenFileDialog1.FilterIndex = 2
OpenFileDialog1.RestoreDirectory = True
If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
myStream = OpenFileDialog1.OpenFile()
If (myStream IsNot Nothing) Then
DataBasePath = OpenFileDialog1.FileName.ToString
End If
Catch Ex As Exception
MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
Finally
If (myStream IsNot Nothing) Then
myStream.Close()
End If
End Try
End If
End If
Con55 = New OleDbConnection(GetProvider(DataBasePath, Password))
Con55.Open()
Dim schemaTable As DataTable = Con55.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
Dim Tables = (From Row As DataRow In schemaTable.Rows Where Row("TABLE_TYPE") = "TABLE" Select Row.Item("TABLE_NAME")).ToArray
ListBox1.Items.Clear()
ListBox1.Items.AddRange(Tables)
Con55.Close()
Catch ex As Exception
If Con55.State = ConnectionState.Open Then Con55.Close()
Password = InputBox("أدخل كلمة المرور لقاعدة البيانات", "كلمة المرور")
If Not String.IsNullOrEmpty(Password) Then
GoTo Sniper
End If
Finally
If Con55.State = ConnectionState.Open Then Con55.Close()
End Try
End Subالله المستعان
