To get a list of table names from database use following code:
Dim sConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\sample.mdb"
Dim olecon As New OleDbConnection(sConn)
olecon.Open()
Dim tblrestrictions As String() = New String() {Nothing, Nothing, Nothing, "TABLE"}
Dim dt As DataTable = olecon.GetSchema("tables", tblrestrictions)
olecon.Close()
GridView1.DataSource = dt
GridView1.DataBind()
Restrictions are a string array in the following format:
{TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE}.
Using ADOX and Msysobjects works fine with windows applications but may problematic for web apps[permission related problems]. If you use Msysobjects directly in query, following error will be displayed:
Record(s) cannot be read; no read permission on 'MSysObjects'
So it's better to use GetSchema with restriction.
2 comments:
This was really helpful for me. Thanx. A great post.
Gayan Munasinghe
I tried a lot....
Ur code only help me to reach the answer....
Thank You Sir....
Thanks a Lot.....
Post a Comment