| | |
Fields in an Access database table
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 271
Reputation:
Solved Threads: 56
why not just google for what he told you?
i straight came to http://msdn.microsoft.com/en-us/libr...e_members.aspx
i straight came to http://msdn.microsoft.com/en-us/libr...e_members.aspx
•
•
Join Date: Aug 2009
Posts: 1
Reputation:
Solved Threads: 1
Hi
the most easiest way is via DAO
- add reference to ms DAO (3.6)
- set vars for database and tabledef and field
dim db as dao.database, dim tdf as dao.tabledef
- get the current database: set db = currentdb()
- get the tabledef as object: set tdf = db.tabledefs("tblName")
- loop the fields for each fld in tdf.fields etc.
- debug.print fld.name etc.
further see the internal help: F1 on as word in the code
good luck
huub
the most easiest way is via DAO
- add reference to ms DAO (3.6)
- set vars for database and tabledef and field
dim db as dao.database, dim tdf as dao.tabledef
- get the current database: set db = currentdb()
- get the tabledef as object: set tdf = db.tabledefs("tblName")
- loop the fields for each fld in tdf.fields etc.
- debug.print fld.name etc.
further see the internal help: F1 on as word in the code
good luck
huub
Arunabh Nag: Here is the C# code I use to enumerate tables and columns. Let me know if you have trouble translating it and I will get back with you tomorrow. I figure a C# answer today is better than a VB.NET answer tomorrow 

VB.NET Syntax (Toggle Plain Text)
using System; using System.Data; using System.Data.Common; using System.Windows.Forms; namespace daniweb { public partial class frmDbSearch : Form { public frmDbSearch() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //if (_conn.ConnectionType == ConnectionWrapperType.ODBC) //{ // SetTableList(@"System.Data.Odbc"); //} //else if (_conn.ConnectionType == ConnectionWrapperType.OleDb) //{ // SetTableList(@"System.Data.OleDb"); //} //else if (_conn.ConnectionType == ConnectionWrapperType.SQL) //{ // SetTableList(@"System.Data.SqlClient"); //} //else if (_conn.ConnectionType == ConnectionWrapperType.Oracle) //{ // SetTableList(@"System.Data.OracleClient"); //} const string fName = @"C:\dotnetwin\dxDelete\dxSample_Q216730(1)\WebSite214\App_Data\nwind.mdb"; string connStr = BuildAccessConnectionString(fName, "Admin", string.Empty, string.Empty); DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb"); using (DbConnection connection = factory.CreateConnection()) { connection.ConnectionString = connStr; connection.Open(); DataTable _dtTables = connection.GetSchema("Tables"); DataTable _dtColumns = connection.GetSchema("Columns"); //At this point you have the tables, columns, views, etc. System.Diagnostics.Debugger.Break(); } } public static string BuildAccessConnectionString(string Filename, string Username, string Password, string DatabasePassword) { return string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='{0}';User Id={1};Password={2};Jet OLEDB:Database Password={3};", Filename.Replace("'", "''"), Username, Password, DatabasePassword); } } }
Also note -- you can just call
connection.GetSchema() off of an existing OleDb or ODBC connection to access... its a lot less work. Using Wrong code....
plz help/.....
VB.NET Syntax (Toggle Plain Text)
Module Module1 'How to get a list of columns from an access database given a table name Dim oleConn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\users.mdb") Dim restrictions() As String = {"", "", "userinfo", ""} Dim SchemaTable As DataTable Public Sub connect() oleConn.Open() SchemaTable = oleConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, _ 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" 'EXCEPTION : Table is not part of table column Then 'Add items to list box Form1.comboselecttable.Items.Add(SchemaTable.Rows(int)!COLUMN_NAME.ToString()) End If '// Get list of tables columns Next 'Form1.comboselecttable.Items.Add(dbRet.Rows(0)!TABLE_NAME.ToString()) '// dbRet will have a column name called "COLUMN_NAME" which will contain all the columns for the table End Sub Public Sub endconn() oleConn.Close() End Sub End Module
plz help/.....
have used another variation that gives a list of the columns....
But the list also contains a set of non-existent columns (Varying with diff databases).Can anyone help..??
some extra column names that appear are...::
Data
ID
Id
LValue
ObjectGuid
ObjectName
Property e.t.c.
But the list also contains a set of non-existent columns (Varying with diff databases).Can anyone help..??
VB.NET Syntax (Toggle Plain Text)
Module Module1 'How to get a list of columns from an access database given a table name Jereme E. Guenther | Edit | Show History Dim oleConn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\password.mdb;Jet OLEDB:Database Password=admin") 'Dim oleConn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\chatusers.mdb;Jet OLEDB:Database Password=admin") 'Dim n As Integer Dim restrictions() As String = {"", "", "password", ""} Dim SchemaTable As DataTable Public Sub connect() oleConn.Open() SchemaTable = oleConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, _ 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 Form1.comboselecttable.Items.Add(SchemaTable.Rows(int)!COLUMN_NAME.ToString()) 'End If '// Get list of tables columns Next 'Form1.comboselecttable.Items.Add(dbRet.Rows(0)!TABLE_NAME.ToString()) '// dbRet will have a column name called "COLUMN_NAME" which will contain all the columns for the table End Sub Public Sub endconn() oleConn.Close() End Sub End Module
some extra column names that appear are...::
Data
ID
Id
LValue
ObjectGuid
ObjectName
Property e.t.c.
Used the following code to get the field names.
the problem now is that apart from the actual field names, i get 7-8 more column names that don't exist in the database.
The extra field names and numbers vary from database to database.
I have uploaded a screenshot showing the fieldnames.
only the password column actually exists
Plz help......
VB.NET Syntax (Toggle Plain Text)
Module Module1 'How to get a list of columns from an access database given a table name Jereme E. Guenther | Edit | Show History 'Dim oleConn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\password.mdb;Jet OLEDB:Database Password=admin") 'Dim oleConn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\chatusers.mdb;Jet OLEDB:Database Password=admin") Dim oleConn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\contacts.mdb") 'Dim n As Integer 'Dim restrictions() As String = {"", "", "tablename", ""} Dim SchemaTable As DataTable Dim countcols As Integer Public Sub connect() oleConn.Open() SchemaTable = oleConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Columns, _ 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 Form1.comboselecttable.Items.Add(SchemaTable.Rows(int)!COLUMN_NAME.ToString()) 'End If '// Get list of tables columns Next countcols = SchemaTable.Rows.Count Form1.TextBox1.Text = CStr(countcols) 'Form1.comboselecttable.Items.Add(dbRet.Rows(0)!TABLE_NAME.ToString()) '// dbRet will have a column name called "COLUMN_NAME" which will contain all the columns for the table End Sub Public Sub endconn() oleConn.Close() End Sub End Module
the problem now is that apart from the actual field names, i get 7-8 more column names that don't exist in the database.
The extra field names and numbers vary from database to database.
I have uploaded a screenshot showing the fieldnames.
only the password column actually exists
Plz help......
![]() |
Similar Threads
- problem getting short time from an MS access database (C#)
- how to save information from a online form to MS access database (ASP)
- Connection.Execute command to Delete Records from MS Access Database Table (Visual Basic 4 / 5 / 6)
- Connect MS Access database table to crystal report, Pls help me (VB.NET)
- how to save a file in a database table (Visual Basic 4 / 5 / 6)
- Updating columns in an access database using c# (C#)
- Reading an Access Database (VB.NET)
- inserting variable value into fields in access? (Visual Basic 4 / 5 / 6)
- load data from access database into form (VB.NET)
Other Threads in the VB.NET Forum
- Previous Thread: Application settings default export map
- Next Thread: installing
Views: 979 | Replies: 15
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
"crystal .net .net2005 2008 access add application array assignment basic box button buttons center class click code combo convert cpu data database datagrid datagridview design designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees error excel exists firewall function image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net opacity page pan picturebox port print printing printpreview problem record refresh regex reports" reuse right-to-left save savedialog search serial socket sorting sql sqldatbase storedprocedure string structures studio temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet vista visual visualbasic visualbasic.net visualstudio2008 web wpf xml






