Click here to Skip to main content
15,922,584 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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]
Posted
Updated 28-Feb-11 21:58pm
v2

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.
 
Share this answer
 
Comments
Dylan Morley 1-Mar-11 4:07am    
my 5!
Yasser El Shazly 1-Mar-11 4:21am    
this is the procedures
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[SP_selectall_medarabicname]
as
begin
select Name_arabic from Med
end
Yasser El Shazly 1-Mar-11 4:24am    
how can i use my debugger to solve that..?
Sandeep Mewara 1-Mar-11 4:33am    
Put a break point in your Visual Studio and then see what is the structure in table object.
Then see in 'dr' object.
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:
 
Share this answer
 
Comments
Yasser El Shazly 1-Mar-11 4:24am    
how i can use my debugger to solve that..?
Dylan Morley 1-Mar-11 4:34am    
Put a breakpoint after the line DataTable table = ds.Tables["Med"];

Now go to your 'Locals' tab in your debugger. See the variable 'table' is in there. Expand it. Find the 'Rows' property. Expand it. Find the Table property. Expand it. Find the Columns property. Expand it. Find the List property. Expand it

Now you'll see the Array of DataColumn items that represent the columns in your DataTable

You can expand any one & look at the Columns Name property. Does your column exist?
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.


 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900