I Love Stackoverflow
I Love Stackoverflow

Reputation: 6868

Not getting columns of specific tables of MySQL

I am trying to fetch column details of MySQL database with following details:

Code:

String[] columnRestrictions = new String[4];
                    // For the array, 0-member represents Catalog; 
                    // 1-member represents Schema; 
                    // 2-member represents Table Name; 3-member represents Column Name. 
                    // Now we specify the Table_Name and Column_Name of the columns what we want to get schema information.
                    //Reference:https://msdn.microsoft.com/en-us/library/ms136366(v=vs.110).aspx
                    columnRestrictions[0] = 'student';
                    columnRestrictions[1] = 'student';
                    columnRestrictions[2] = 'student_detail'

DataTable allColumnsSchemaTable = con.GetSchema("Columns"); //giving me all columns of all tables
// not getting columns
var cols = con.GetSchema("Columns", new string[] { 'student','student' "student_detail" }).AsEnumerable().Select(col => col["COLUMN_NAME"].ToString()).ToArray();
// not getting columns
var cols = con.GetSchema("Columns", new string[] { 'student',"student_detail" }).AsEnumerable().Select(col => col["COLUMN_NAME"].ToString()).ToArray();

Now this is working fine but giving me all columns of all tables:

DataTable allColumnsSchemaTable = con.GetSchema("Columns"); //giving me all columns of all tables

I want to get columns of specific tables.

Update: In my research I found that there is nothing like schema in MySQL which is in MSSQL so in MySQL schema and database are same

Upvotes: 1

Views: 116

Answers (1)

I Love Stackoverflow
I Love Stackoverflow

Reputation: 6868

I manage to solve this problem in following way:

I moved database position from 0th to 1st but in case of mssql database position will be at 0th position as because there is no such concept like schema in case of mysql

// For the array, 0-member represents Catalog; 
 // 1-member represents Schema; 
 // 2-member represents Table Name; 3-member represents Column Name. 
 // Now we specify the Table_Name and Column_Name of the columns what we want to get schema information.

    String[] columnRestrictions = new String[4];
    columnRestrictions[1] = "student"; //database name is specified in place of schema
    columnRestrictions[2] = student_detail"

Upvotes: 2

Related Questions