System.Data.ODBC difficulties

  • Thread starter Thread starter Sergey
  • Start date Start date
S

Sergey

Hello,

I'm using an ODBC driver for MySql and the ODBC classes
that come with .NET framework.

I don't know how to do the following tasks:

1. Determining if a table with a given name exists in the
database.
2. Creating a data source programmatically.
3. Creating a database programatically.

Any help would be appreciated,
--Sergey
 
...
I'm using an ODBC driver for MySql and the ODBC classes that come with
..NET framework.
I don't know how to do the following tasks:
1. Determining if a table with a given name exists in the database.
2. Creating a data source programmatically.
3. Creating a database programatically.

Could you be a little more specific?

You can pass SQL commands in through the OdbcCommand object, but as far as
I'm aware, you cannot pass batch commands through ODBC.

There is a MySQL utility available for batch commands (I don't remember the
name) which you could access through PInvoke.
 
I don't know how to do the following tasks:
Could you be a little more specific?

OK, let's focus on 1-- checking if a table exists in the
database. Using classes from System.Data.OleDb, I can
write the following routine:
=====================================================
bool DoesTableExist(string tableName, OleDbConnection
dbConn)
{
DataTable tabsTable = dbConn.GetOleDbSchemaTable
(OleDbSchemaGuid.Tables, null);
foreach (DataRow row in tabsTable.Rows)
{
if (((string)(row["TABLE_NAME"])).Equals(tableName))
return true;
}
return false;
}
=============================================
Do .NET ODBC classes allow to write a routine equivalent
to this one? If not, how do I do it, other than with the
method above (a link to code that does this would help)?

Thank you,
--Sergey
 
OK, let's focus on 1-- checking if a table exists in the database. Using
classes from System.Data.OleDb, I can write the following routine: . . .

From MSDN: cpconObtainingSchemaInformationFromDatabase.htm

The .NET Framework Data Provider for SQL Server and .NET Framework Data
Provider for ODBC expose schema information through functionality provided
by your specific data source such as stored procedures and informational
views.

To obtain schema information from a data source the .NET Framework Data
Provider for ODBC uses the same method as the .NET Framework Data Provider
for SQL Server.

In other words, you need to use the MYSQL commands available to do this.
 
Back
Top