Click here to Skip to main content
15,353,677 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
DataTable dt = new DataTable();
DateTime time = DateTime.Now.AddHours(10.30);
dt =DAL.Registration_Master.View(time).ToString();//error


//Error Cannot implicitly convert type 'string' to 'System.Data.DataTable'

//What is the solution for that?

Even when i convert it like

dt =Convert.ToDateTime(DAL.Registration_Master.View(time).ToString());

but still it gives me error..
Posted
Updated 11-Dec-12 22:58pm
v2
Comments
choudhary.sumit 12-Dec-12 4:55am
   
what you want to do with this piece of code??
Mendor81 12-Dec-12 4:58am
   
I don't get what your trying to do, i suppose that in the datatable you try to fill in a field with the current time.
What is this line? "DAL.Registration_Master.View(time)" ??

The error is pretty clear you can't cast datetime into a datatable object via string.
choudhary.sumit 12-Dec-12 5:01am
   
what are you doing? what is your purpose?? be clear?

You are trying to assign String value to DataTable.
C#
dt =Convert.ToDateTime(DAL.Registration_Master.View(time).ToString());

You cannot directly assign string value to DataTable.
   
you can assign the values to data table after creating columns into it.
I guess, you may want code like this
C#
string dtt = DAL.Registration_Master.View(time).ToString();
DataTable dt = new DataTable();
DataColumn dc = new DataColumn();
dc.ColumnName = "Date";
dt.Columns.Add(dc);
dt.Rows.Add(dtt);


--Sj
   

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