23-12-15, 10:29 AM
بسم الله الرحمن الرحيم
اخي hamada558 شكر على المشاركة تم تجرية الكود وتم وضع أداة OpenFileDialog1 من أدوات الفجوال ولكن ظهر لي خطأ كما في الصورة
اخي hamada558 شكر على المشاركة تم تجرية الكود وتم وضع أداة OpenFileDialog1 من أدوات الفجوال ولكن ظهر لي خطأ كما في الصورة
(22-12-15, 02:12 PM)hamada558 كتب : جرب وخبرني
كود :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim OpenFile As New OpenFileDialog With {
.Filter = "Access (*.mdb;*.accdb)|*.mdb;*.accdb;|Excel (*.xls;*.xlsx)|*.xls;*.xlsx;",
.Title = "Select a Cursor File"
}
If OpenFile.ShowDialog() = DialogResult.OK Then
Con55.ConnectionString = GetProvider(OpenFile.FileName)
Dim password As String = ""
Try
Con55.Open()
Catch ex As Exception
password = InputBox("قاعدة البيانات قد تتطلب كلمة مرور")
Con55.ConnectionString = GetProvider(OpenFile.FileName, password)
End Try
ListBox1.Items.Clear()
Try
If Con55.State <> ConnectionState.Open Then Con55.Open()
Dim schemaTable As DataTable = Con55.GetSchema("Tables", New String() {Nothing, Nothing, Nothing, "Table"})
Con55.Close()
Dim Tables = (From r In schemaTable Select r("TABLE_NAME")).ToArray
ListBox1.Items.AddRange(Tables)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
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
سؤال هل انت واضع أداة OpenFileDialog1 من أدوات الفجوال؟
الله المستعان
