2010-12-01 70 views
1

我有这样的功能在同一个类调试所赐的结果,但没有得到填充

public static DataSet GetAllUppercasedTables() 
{ 
    //An instance of the connection string is created to manage the contents of the connection string. 
    using(var sConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"])) 
    { 
    //To Open the connection. 
    sConnection.Open(); 

    //Query to select the tables having their names in uppercased format. 
    string selectUppercasedTables = @"SELECT NAME 
             FROM sysobjects 
             WHERE UPPER(name) COLLATE Latin1_General_BIN = name COLLATE Latin1_General_BIN 
             AND OBJECTPROPERTY(ID,N'IsTable')=1 
             AND OBJECTPROPERTY(ID,N'IsMSShipped')=0 "; 
     //Create the command object 
     using(var sCommand = new SqlCommand(selectUppercasedTables, sConnection)) 
     { 
     try 
     { 
      //Create the dataset. 
      DataSet dsUppercasedTables = new DataSet("INFORMATION_SCHEMA.TABLE_CONSTRAINTS "); 

      //Create the dataadapter object. 
      SqlDataAdapter da = new SqlDataAdapter(selectUppercasedTables, sConnection); 

      //Provides the master mapping between the sourcr table and system.data.datatable 
      da.TableMappings.Add("Table", "INFORMATION_SCHEMA.TABLE_CONSTRAINTS "); 

      //Fill the dataadapter. 
      da.Fill(dsUppercasedTables); 

      //Bind the result combobox with non primary key table names 
      DataViewManager dsv = dsUppercasedTables.DefaultViewManager; 
      return dsUppercasedTables; 
     } 
     catch(Exception ex) 
     { 
      //Handles the exception and log that to the EventLog with the original message. 
      EventLog log = new EventLog("Application"); 
      log.Source = "MFDBAnalyser"; 
      log.WriteEntry(ex.Message); 
      return null; 
     } 
     finally 
     { 
      //checks whether the connection is still open. 
      if(sConnection.State != ConnectionState.Closed) 
      { 
      sConnection.Close(); 
      } 
     } 
     } 
    } 
    } 

,我在另一个类调用这个函数像这样

public void GetTablesWithUpperCaseName() 
{ 
    DataSet dsUppercasedTables = default(DataSet); 
    try 
    { 
    dsUppercasedTables = DataAccessMaster.GetAllUppercasedTables(); 

    **dgResultView.DataSource** = dsUppercasedTables.Tables["INFORMATION_SCHEMA.TABLE_CONSTRAINTS"]; 
    } 
    catch(Exception ex) 
    { 
    //All the exceptions are handled and written in the EventLog. 
    EventLog logException = new EventLog("Application"); 
    logException.Source = "MFDBAnalyser"; 
    logException.WriteEntry(ex.Message); 
    } 
} 

我在调试它几乎每一个要求的点,它都给出了很好的结果,直到dgResultView.DataЫource....

任何人都可以帮助我!

+1

提供异常抛出 – 2010-12-01 13:20:09

回答

2

反正换你SqlConnectionDataSetSqlDataAdapterusing块了。