我一直對我的這部分代碼得到空引用異常:空引用異常樹視圖
enumerator = this.Ds_Settings1.Tables["Settings_RefreshForm_ScriptMgmt_SelectALL"].Rows.GetEnumerator();
任何幫助是極大的讚賞。
以下是整個代碼。這是創建一個樹形視圖,使用存儲過程的數據集列出所有腳本。
private void Refresh_Form()
{
IEnumerator enumerator = null;
IEnumerator enumerator1 = null;
IEnumerator enumerator2 = null;
try
{
this.tv_Scripts.Nodes.Clear();
this.tv_Scripts.Nodes.Add(Conversions.ToString(0), "Standard Fixes");
this.tv_Scripts.Nodes.Add(Conversions.ToString(0), "SQL Agent Updates");
this.tv_Scripts.Nodes.Add(Conversions.ToString(0), "Other");
try
{
enumerator = this.Ds_Settings1.Tables["Settings_RefreshForm_ScriptMgmt_SelectALL"].Rows.GetEnumerator();
while (enumerator.MoveNext())
{
DataRow script = (DataRow)enumerator.Current;
try
{
enumerator1 = this.tv_Scripts.Nodes.GetEnumerator();
while (enumerator1.MoveNext())
{
TreeNode ParentNode = (TreeNode)enumerator1.Current;
if (Microsoft.VisualBasic.CompilerServices.Operators.CompareString(ParentNode.Text, script[4].ToString(), false) != 0)
{
continue;
}
ParentNode.Nodes.Add(script[1].ToString(), script[1].ToString(), 1, 1);
int index = ParentNode.Index;
this.TreeNode_SetStateImageIndex(ParentNode, Conversions.ToInteger(index.ToString()));
}
}
finally
{
if (enumerator1 is IDisposable)
{
(enumerator1 as IDisposable).Dispose();
}
}
}
}
finally
{
if (enumerator is IDisposable)
{
(enumerator as IDisposable).Dispose();
}
}
this.cmb_Environment.Items.Clear();
try
{
enumerator2 = this.Ds_Settings1.Tables["Settings_Environments_Select"].Rows.GetEnumerator();
while (enumerator2.MoveNext())
{
object env = RuntimeHelpers.GetObjectValue(enumerator2.Current);
object[] objArray = new object[] { 5 };
if (!Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(NewLateBinding.LateIndexGet(env, objArray, null), true, false))
{
continue;
}
ComboBox.ObjectCollection items = this.cmb_Environment.Items;
object[] objArray1 = new object[] { 1 };
items.Add(NewLateBinding.LateIndexGet(env, objArray1, null).ToString());
}
}
finally
{
if (enumerator2 is IDisposable)
{
(enumerator2 as IDisposable).Dispose();
}
}
this.tv_Scripts.ExpandAll();
}
catch (Exception exception)
{
ProjectData.SetProjectError(exception);
this.DisplayOnly_ErrorHandler("ERROR REFRESHING FORM DATA: ", exception.Message, MsgBoxStyle.Critical);
ProjectData.ClearProjectError();
}
}
這裏的堆棧跟蹤:
在SQLRefreshTool.SQLRefreshTool.Refresh_Form()在C:\用戶\ BSantiago \文檔\ Visual Studio 2010的\項目\ SQLRefreshTool \ SQLRefreshTool \ Form1.cs中: (C:\ Users \ BSantiago \ Documents \ Visual Studio 2010 \ Projects \ SQLRefreshTool \ SQLRefreshTool \ Form1.cs中的SQLRefreshTool.SQLRefreshTool..ctor()中的179 SQL:SQLRefreshTool.Program.Main() \ Users \ BSantiago \ documents \ visual studio 2010 \ Projects \ SQLRefreshTool \ SQLRefreshTool \ Program.cs:line 18 at System.AppDomain._nExecuteAssem bly(Assembly assembly,String [] args) at System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper。 ThreadStart_Context(對象狀態) 在System.Threading.ExecutionContext.Run(ExecutionContext中的ExecutionContext,ContextCallback回調,對象狀態) 在System.Threading.ThreadHelper.ThreadStart()
你可以發佈堆棧跟蹤嗎? –
已發佈堆棧跟蹤。 – user2844189