How can I use the GetSchema method new in 2.0 to get a list of only user tables and views.
By defautl, GetSchema will return tables that belong to dbo schema. In SQL2005, all system tables/views belong to sys schema. If you want to get schema for objects that belong to a specific user, you should set the 2nd restriction value to the owner name. For example:
string connectionString = "Data Source=(local);Database=master;Integrated Security=SSPI;";
using (SqlConnection connection =
new SqlConnection(connectionString))
{
//Connect to the database, and then retrieve the
//schema information.
connection.Open();
string[] restrictions = new string[4];
restrictions[1] = "iori";
DataTable table = connection.GetSchema("Tables", restrictions);
// Display the contents of the table.
foreach (System.Data.DataRow row in table.Rows)
{
foreach (System.Data.DataColumn col in table.Columns)
{
Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
}
Console.WriteLine("============================");
}
Console.WriteLine("Press any key to continue.");
}
For more info, please go to this website:
http://msdn2.microsoft.com/en-us/library/ms254934.aspx|||
When I changed the string as follows to access db. I am getting the error. Please help! thanks
myConnectionString ="Provider=Microsoft.Jet.Oledb.4.0; Data Source=c:AjaxSureAcc/App_Data/AccountInfo.mdb";
Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.ArgumentException: Keyword not supported: 'provider'.
never mind the above. I figured it out. I should have been using oleDBConnection
No comments:
Post a Comment