Click here to Skip to main content
14,825,830 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
i have a code in :
Dim oDs As DataSet = GridView1.DataSource

and when i run this code,it shows no error.

when i convert to c-sharp :
DataSet oDs = GridView1.DataSource;<br />

it shows error:
Cannot implicitly convert type 'object' to 'System.Data.DataSet'. An explicit conversion exists (are you missing a cast?)

can anyone help me on this,i had been scratching my head for 2 days for this..i dont understand what is the cast means,what should we do with the code.
Jason Vetter 2-May-11 9:18am
Had you been using Option Strict On and Option Explicit On as you ALWAYS should be you would have caught the same error.

Dim oDs As DataSet = DirectCast(GridView1.DataSource, DataSet)


This is working with VB because in VB implicit conversion exists.
But in case of C#, you need to provide type cast information.
In C#, There is no implicit conversion.

Try this code
DataSet oDs = (DataSet)GridView1.DataSource;

It might help you.

pwtc222 2-May-11 8:38am
thanks dude..that works :-)
Try this:

Dataset ds=new Dataset();

//Write your query..


DataSet oDs = (DataSet)GridView1.DataSource;
pwtc222 2-May-11 8:39am
Thanks friend..that works..really appreciate it :-)
Member 11011853 3-Jun-15 4:25am

GVemp.DataSource= ef.Select_EmpId(eid);
DataTable t = (DataTable)GVemp.DataSource;
txtAddress.Text = t.Rows[0]["Address"].ToString();
txtName.Text = t.Rows[0]["EmpName"].ToString();

i converted object type to datatable type in the above code, but i shows error as cant convert object type to datatable type...

Any help appreciated...!

thank u...!
R. Giskard Reventlov 3-Jun-15 10:36am
Try something like:

DataSet ds = (DataSet)GVemp.DataSource;
DataTable dt = ds.Tables[0];

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