调试给出结果但未填充
我在一个类中有一个这样的函数
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....
谁能帮帮我!
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.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();
}
}
}
}
}
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论如何,也将您的
SqlConnection
、DataSet
和SqlDataAdapter
封装在using
块中。Anyway wrap your
SqlConnection
,DataSet
andSqlDataAdapter
withinusing
block too.