从数据表中检索数据所有行来自数据表 [英] Retreveing Data From Data table All Rows From data table
问题描述
我有以下代码从数据库中检索数据,我得到了跟随的错误
任何人都可以帮我解决这个问题
DataTable table = ds.Tables [Med];
foreach(table.Rows中的DataRow dr)
{
lst_ArabNames.Add(dr [Name_arabic]。ToString());
} //结束每个
以下错误即将发生
列'Name_arabic'不属于表Med。
但是它已经是表格中的一列Med
可以帮助我解决这个问题
谢谢
:((
[edit]忽略HTML ...选项已禁用:允许代码块工作 - OriginalGriff [/ edit]
< blockquote> 列'Name_arabic'不属于表Med。 \
这只是意味着,它不是!
但它已经是表格中的一列Med
你们其中一个人错了,你们的IDE运行时还是你们。我会抓住你们错的机会。
任何人都可以帮助我解决这个问题
使用VS Debugger,看看对象是dr还是table里面有一个名为'Name_arabic'的列?这应该清除掉的东西。
PS:查询中给出的名称是它的意思反映在数据中。可能是您在数据库中有名称为Name_arabic的列,但它在查询中有别名。
如果仍然无法解析,请分享用于填充数据集的查询(从中获取表格)。您可能使用XML而不是查询,然后共享它。
错误告诉您问题是什么,您尝试访问表中不存在的列
使用您的调试器,您可以使用本地和直接窗格来确定发生了什么,
这不是骗你的,你认为这个列存在于表中,但是它的拼写可能略有不同,或者你没有正确地从DataSet中引用它。
使用你的调试器,你可以解决这个问题:thumbsup:
这可能会对你有所帮助。
DataTable table = ds.Tables [0];
foreach(table.Rows中的DataRow dr)
{
lst_ArabNames.Add(dr [Name_arabic]。ToString());
} //每个结束
说明:我不确定当你填充数据集时,那个时候你将数据表命名为'Med'。但是,幸运的是,如果你没有命名它,那么我所提供的应该可以工作。
这是因为你可能然后只是使用查询结果集填充数据集,并且前端不会知道'Med'指的是什么?
HTH
问候,
Rajeev
如果这对您有帮助,请投票并将答案标记为已接受。
hi i have the following Code To retrieve data from Data base and i get the followed error
can any one help me in solving that
DataTable table = ds.Tables["Med"]; foreach (DataRow dr in table.Rows) { lst_ArabNames.Add(dr["Name_arabic"].ToString()); }// end for each
the following error is comming
Column 'Name_arabic' does not belong to table Med.
but it is already a column in the table Med
can any one help me in solving that
thanks
:((
[edit]"Ignore HTML..." option disabled: allows code block to work - OriginalGriff[/edit]
Column 'Name_arabic' does not belong to table Med.\
This simply means, it's not!
but it is already a column in the table Med
One of you is wrong, your IDE runtime or You. I will take a chance that you are wrong.
can any one help me in solving that
Use VS Debugger, and see does the object dr or table has a column named 'Name_arabic' in it? That should clear out the things.
P.S.: The name given in the query is what it would reflect in data. May be you have the column with name 'Name_arabic' in database but it's aliased something else in query.
If you are still unable to resolve, share the query using which you filled the dataset (from which you got your table). Might be you used XML instead of query, then share that.
The error is telling you what the problem is, you've tried to access a column that does not exist in the table
Use your debugger, you can use the locals & immediate panes to determine exactly what's going on,
It's not lying to you, you think the column exists in the table but maybe it's spelt slightly differently or you haven't referenced it from the DataSet correctly.
Using your debugger, you can solve this :thumbsup:
May be this is what will help you.
DataTable table = ds.Tables[0]; foreach (DataRow dr in table.Rows) { lst_ArabNames.Add(dr["Name_arabic"].ToString()); }// end for each
Explanation: I am not sure when you filled your dataset, that time you named the datatable as 'Med'.But if, fortunately, you wouldn't have named it then what I have given should work.
This is because you may be then just populating the dataset with the query result-set and in no way is the front-end aware of what is 'Med' referring to ?
HTH
Regards,
Rajeev
Please vote and mark the answer as accepted if this helps you.
这篇关于从数据表中检索数据所有行来自数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!