17-09-12, 02:41 PM
اولا عرف متغير اتصال بالقاعدة مثلا
رمز برمجي:
ثانيا انسخ الدالة التالية وضعها بموديول
رمز برمجي:
ثم بحدث النقر لزر الامر اكتب
رمز برمجي:
رمز برمجي:
كود :
Dim str As String = "provider=microsoft.ace.oledb.12.0 ; data source=|datadirectory|\db.accdb"
ثانيا انسخ الدالة التالية وضعها بموديول
رمز برمجي:
كود :
Public Function DoesTableExist(ByVal tblName As String, ByVal cnnStr As String) As Boolean
' For Access Connection String,
' use "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
' accessFilePathAndName
' Open connection to the database
Dim dbConn As New OleDbConnection(cnnStr)
dbConn.Open()
' Specify restriction to get table definition schema
' For reference on GetSchema see:
' http://msdn2.microsoft.com/en-us/library/ms254934(VS.80).aspx
Dim restrictions(3) As String
restrictions(2) = tblName
Dim dbTbl As DataTable = dbConn.GetSchema("Tables", restrictions)
If dbTbl.Rows.Count = 0 Then
'Table does not exist
DoesTableExist = False
Else
'Table exists
DoesTableExist = True
End If
dbTbl.Dispose()
dbConn.Close()
dbConn.Dispose()
End Function
رمز برمجي:
كود :
If DoesTableExist(InputBox("اكتب اسم جدول"), str) Then
MsgBox("موجود", MsgBoxStyle.Information, "")
Else
MsgBox("غير موجود", MsgBoxStyle.Critical, "")
End If