Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 29, 2012 10:49 PM by Prysson
Feb 28, 2012 09:03 PM|LINK
I want to be able to query a mysql database...knowing the tablename...but not knowing the column in that table or their datatypes and size restrictions and be able to retrieve that information...
How can I do that in c#?
Feb 29, 2012 08:51 AM|LINK
Try this sql from your c# code
"SHOW COLUMNS FROM mytable FROM mydb";
then iterate the returned data and fetch your desired column name and data type.
Feb 29, 2012 10:49 PM|LINK
Thanks for the Query. Works like a charm.
Anyone who may not know how to evaluate the data in c# as its returned from the query the following will work
MySqlConnection msql = new MySqlConnection();
msql.ConnectionString = "connectionstringinfo";
MySqlDataAdapter myAdapter = new MySqlDataAdapter("SHOW COLUMNS FROM mytable", msql);
"SHOW COLUMNS FROM mytable", msql);
DataSet ds = new DataSet();
DataTable dt = ds.Table;
then parse through the datatable columns and you will have yoru column names and data types.