2016-12-15 7 views
1

Я пытаюсь извлечь детали столбцов базы данных MySQL с следующими деталями:не получают столбцы конкретных таблиц MySQL

  • Имя базы данных = студент
  • Table Name = 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 

Я хочу получить столбцы конкретных таблиц.

Update: В моем исследовании я обнаружил, что там нет ничего, как схемы в MySQL, которая находится в MSSQL так в MySQL схемы и базы данных являются одинаковыми

+0

Это неправильный строковый массив. '{'student', 'student'" student_detail "}'. Строки должны иметь qutoes '' 'и между student и student_detail, должна быть другая запятая. – Phiter

+0

@PhiterFernandes Извините, что это была ошибка, но это не проблема –

+0

попробуйте http://stackoverflow.com/questions/17353089/get-the -column-names-of-a-table-and-store-them-in-a-string-or-var-c-sharp-asp-ne – Damith

ответ

3

мне удалось решить эту проблему следующим образом:

я переехал позицию базы данных из 0-го до 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"