更新时间:2023-10-06 14:04:22
在我离开之前...我想我发现了问题.您处置连接,然后再也不创建新的连接.您不需要处理它...但是,如果要这样做,请在之后立即将其设置为新的连接.
我正在尝试遵循逻辑...如果我离开了,请告诉我
您的页面上只有一个DropDownListBox
.第一次,我不能告诉您是否应该首先检查类别或语言.我假设应该先检查语言.
如果是这样,它将使用语言"选项填充列表框.然后将CheckLanguage
设置为true,将CheckCategory
设置为false.这两个存储在ViewState
中,应在回发时进行维护.
然后,必须将m_CheckCategory
设置为true
,以确保它不会加载列表框中的类别"选项.至于良好的编码,为什么不使用return;
代替m_CheckCategory = true;
?您无需在该代码部分中进行任何其他操作,只需退出子例程即可.
因此,下次,它会检查ViewState
和CheckLanguage
应该是true
并且CheckCategory
应该是false
,这会将类别加载到列表框中.
因此,对于第一个答案,将CheckCategory
设置为true
的原因.
但是,对于最初的问题...您是否已第二次执行步骤以查看出了什么问题?m_DT.Columns[m_ColumnName]
中有什么吗?看起来您有两个表...一个CK_Language
和一个CK_Category
其中只有一列...与表名称相同.列名设置正确吗?
至于标准编码实践,如果要检查m_CheckLanguage
或m_CheckCategory
到false
,为什么还要将它们设置为false
?这与常识相反.如果m_CheckLanguage
设置为true
,则将假定您应该检查语言.您是否意识到您将m_DbName
传递给您的OpenConnection
,然后再也不使用它了?短语OpenConnection
表示您只是在打开连接.尝试使用PopulateDataTable
代替.您还要创建一个CommandBuilder
,然后再将其用于任何用途.我也不确定dropDownListCategory
和dropDownListLanguage
的来源.
下次,遍历每个步骤,看看它是否按照预期的方式工作.您应该第二次访问m_Con.ConnectionString
并看到它已被丢弃.
Before I go off...I think I found the problem. You Dispose of the connection and then never create a new one. You don''t need to dispose of it...but if you''re going to, set it to a new connection right after.
I''m trying to follow the logic...tell me if I''m off
You have a singleDropDownListBox
on your page. The first time through, I can''t tell if Category or Language is supposed to be checked first. I''ll assume that Language is supposed to be checked first.
If so, it populates the listbox with Language options. It then setsCheckLanguage
equal to true andCheckCategory
equal to false. Those two are stored inViewState
which should be maintained on postbacks.
Then, you have to setm_CheckCategory
totrue
to make sure it doesn''t load the Category options in the listbox. As to good coding, why not instead ofm_CheckCategory = true;
just usereturn;
? You don''t need to do anything else in that section of code, you can simply quit the subroutine.
So, the next time around, it checks theViewState
andCheckLanguage
should betrue
andCheckCategory
should befalse
, which should load the categories into the listbox.
So, to the first answer, there''s a reason whyCheckCategory
is set totrue
.
But, to the original question...have you stepped through the second time to see what''s going wrong? Is there anything inm_DT.Columns[m_ColumnName]
? It looks like you have two tables...oneCK_Language
and oneCK_Category
that have only one column in them...with the same name as the table. Are the column names set correctly?
And as to standard coding practice, why do you set them_CheckLanguage
orm_CheckCategory
tofalse
if you''re supposed to check them? That''s opposite of common sense. Ifm_CheckLanguage
is set totrue
, you would assume you were supposed to check the language. And do you realize that you pass inm_DbName
to yourOpenConnection
and then never use it? And the phraseOpenConnection
implies that you''re just opening the connection. Try,PopulateDataTable
instead. You also create aCommandBuilder
and then never use it for anything. I''m also not sure wheredropDownListCategory
anddropDownListLanguage
come from.
Next time, go through each step and see if it''s working the way it''s supposed to. You should have gotten tom_Con.ConnectionString
the second time and see that it was disposed of.
m_CheckCategory = true;
}
if (m_CheckCategory == false)
{
此代码可能是您的问题.
您将m_CheckCategory设置为true.
然后,您运行If
条件来检查是否是false
来填充其他列表框(显然永远不会运行).
您的逻辑可能需要更正.
This code could be your problem.
You set m_CheckCategory to true.
You then run a If
condition to check if it is false
to populate your other list box (which obviously will never run).
Your logic here might need to be corrected.