Debugging is giving result but not getting populated
I have a function like this in one class
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.DefaultView开发者_开发知识库Manager;
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();
}
}
}
}
}
And I am calling this function in another class like this
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);
}
}
I have debugged it at almost every required point, it is giving fine result till the dgResultView.DataЫource....
Can anybody help me out!
Anyway wrap your SqlConnection, DataSet and SqlDataAdapter within using block too.
加载中,请稍侯......
精彩评论