We help IT Professionals succeed at work.

"Cannot implicitly convert type 'object' to 'System.Data.DataColumn'

FrancineTaylor
on
1,058 Views
Last Modified: 2008-01-16

This is the code:

      DataSet ds = GetDataSet(psTable, psSQL);
      DataColumn dc = ds.Tables[0].Rows[0][piColumn];

The second line gives the error in the title.  I'm converting my code from VB.NET to C#.NET and I'm obviously not getting the syntax quite right.
Comment
Watch Question

Brian MulderFreelance
Top Expert 2006

Commented:
Hello FrancineTaylor,

you could try something like
--------------
DataColumn dc = New DataColumn[] {ds.Tables[0].Columns["piColumn"]};
--------------

hope this helps a bit
bruintje

Commented:

ds.Tables[0].Rows[0][piColumn]; => Returns the data as thr 0th row of the piColumn as object.
If you want to get the datacolumn you should use
   ds.Tables[0].Columns[0]
the problem is not casting problem. More than it.
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.