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...
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.
Regards,
Moinul Hasan
Senior Software Engineer
Ennovia Technologies Limited
(Mark it as answer if it does help you!)
Marked as answer by Prysson on Feb 29, 2012 10:49 PM
Prysson
Member
62 Points
274 Posts
How can I identify the column names and datatypes of a datatable in MySQL database using c#
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#?
mamun22s
Member
537 Points
135 Posts
Re: How can I identify the column names and datatypes of a datatable in MySQL database using c#
Feb 29, 2012 08:51 AM|LINK
Dear Prysson,
Senior Software Engineer
Ennovia Technologies Limited
(Mark it as answer if it does help you!)
Prysson
Member
62 Points
274 Posts
Re: How can I identify the column names and datatypes of a datatable in MySQL database using c#
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(
DataSet ds = new DataSet();
ds.Tables.Add(dt);
myAdapter.Fill(ds.Tables[0]);
DataTable dt = ds.Table[0];
then parse through the datatable columns and you will have yoru column names and data types.