没有得到MySQL

时间:2016-12-15 10:19:56

标签: c# mysql ado.net

我正在尝试使用以下详细信息获取MySQL数据库的列详细信息:

  • 数据库名称=学生
  • 表名= student_detail

代码:

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();

现在这个工作正常但给了我所有表的所有列:

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

我想获得特定表格的列。

更新:在我的研究中,我发现MySQL中的模式没有像MSSQL中那样,所以MySQL模式和数据库是相同的

1 个答案:

答案 0 :(得分:3)

我设法通过以下方式解决这个问题:

我将数据库位置从 0th移到第1 但是在mssql数据库位置的情况下将位于第0位,因为没有这样的概念 喜欢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"