[Mono-list] Database Schema

Dan dan@astusa.com
Fri, 7 May 2004 15:28:43 -0400

If your using an OleDbConnection you can get a database table schema without
performing a query by using the GetOleDbSchemaTable method.  A DataTable is
returned with detailed schema information.  I added a column to translate
the OleDbType types to their string equivalants for clarity.

		private DataTable GetTableSchema(OleDbConnection conn,
string strDbase, string strTable)
			Object[] filters = new Object[4];
			filters[0] = strDbase;
			filters[1] = null;
			filters[2] = strTable;
			filters[3] = null;
			DataTable tblSchema =
conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, filters);
			Type colType = Type.GetType("System.String");
			tblSchema.Columns.Add("TYPE", colType);
			OleDbType dbColType;
			foreach(DataRow myRow in tblSchema.Rows)
				dbColType =
				myRow["TYPE"] = dbColType.ToString();
			return tblSchema;

Obviously, make sure you using the System.Data and System.Data.OleDb
namespaces and referencing System.Data.dll in your build.

Dan Maltes

-----Original Message-----
From: mono-list-admin@lists.ximian.com
[mailto:mono-list-admin@lists.ximian.com] On Behalf Of Pedro Santos
Sent: Thursday, May 06, 2004 11:08 AM
To: mono-list@ximian.com
Subject: [Mono-list] Database Schema

What's the best way to get the Database schema? The only way I see is to
perform a query to a DataSet and get get the schema from the DataSet. Is
there any other way?
I want to generate an application to CRUD a database. For example, to
generate the form/page to modify a row I would create one control for each
field (based on the filed type), and then update the Database on submit.
Whats the best way to accomplish this? Also, where can I get you code to
generate typed Dataset's? I think it would help me on this task.
Mono-list maillist  -  Mono-list@lists.ximian.com