الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كو د يحدد هل يوجد جدول في القاعدة

بدأه atefkhalf2008 في 2 سبتمبر 2012 · 0 رد · 623 مشاهدة · في ADO.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1

لو سمحت

عايز استخلص من الكود السابق كو د يحدد هل يوجد جدول في القاعدة اسمه مثلا table1 ام لا

واذا كان هل يوجد به حقل اسمه emp_name ام لا

شكرا لك

اكواد - (عرض اسماء الجداول في قاعدة ما - عرض اسماء الاعمدة في جدول ما)

اضف الادوات التالية:

Label1

ListBox1

ListBox2

DataGridView1

Button1

في منطقة التصريحات العامة اكتب:

Dim str As String = ""
Dim con As New OleDb.OleDbConnection

في حدث تحميل النموذج اكتب:

Me.Text = My.Application.Info.ProductName
If con.State = ConnectionState.Open Then
con.Close()
End If

في حدث النقر لزر الامر اكتب:

If con.State = ConnectionState.Open Then
con.Close()
End If
Dim dlg As New OpenFileDialog
dlg.Filter = "Access 2007 db (*.accdb)|*.accdb| Access 2003 db (*.mdb)|*.mdb"
If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
If dlg.SafeFileName.EndsWith(".accdb") Then
str = "provider=microsoft.ace.oledb.12.0;data source=" & dlg.FileName
ElseIf dlg.SafeFileName.EndsWith(".mdb") Then
str = "provider=microsoft.jet.oledb.4.0;data source=" & dlg.FileName

End If
con.ConnectionString = str
Label1.Text = "Connected To: " & con.ConnectionString

End If
Dim SchemaTable As DataTable

Try
ListBox1.Items.Clear()
If con.State = ConnectionState.Closed Then
con.Open()
End If
SchemaTable = con.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, Nothing})
Dim int As Integer
For int = 0 To SchemaTable.Rows.Count - 1
If SchemaTable.Rows(int)!TABLE_TYPE.ToString = "TABLE" Then
'Add items to list box
ListBox1.Items.Add(SchemaTable.Rows(int)!TABLE_NAME.ToString())
End If
Next

Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Critical, "")

End Try

في حدث ListBox1_MouseClick

Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter("select * from " & ListBox1.Text & "", con)
ds.Clear()
DataGridView1.DataSource = Nothing
da.Fill(ds, ListBox1.Text)
DataGridView1.DataSource = ds
DataGridView1.DataMember = ListBox1.Text


ListBox2.Items.Clear()
Dim dtable1 As DataTable
dtable1 = con.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Columns, New Object() {Nothing, Nothing, ListBox1.Text, Nothing})

For i = 0 To dtable1.Rows.Count - 1
ListBox2.Items.Add(dtable1.Rows(i).Item(3).ToString)
Next i

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…