I want to get Schema for a table with name "Petro" in SQL SErver after initializing connectionString, I use this Code
conn.open();
conn.getSchema("Tables");
but it returns schema for all the tables. I only want the Petro schema. What should I do?
I want to get Schema for a table with name "Petro" in SQL SErver after initializing connectionString, I use this Code
conn.open();
conn.getSchema("Tables");
but it returns schema for all the tables. I only want the Petro schema. What should I do?
string[] restrictions = new string[4];
restrictions[2] = "Petro";
DataTable table = conn.GetSchema("Tables",restrictions);
Look here for more information: MSDN: Working with the GetSchema Methods
Edit: use GetSchema instead of getSchema
You can retrieve the schema in following way:
string sql = "select * from Petro WHERE 1 = 0";
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();
DataTable schema = reader.GetSchemaTable();
SQL Server solution:
There is a store procedure called sp_columns. When you run that procedure with the table's name as a parameter, it will return the schema just for that table.