为什么我会发现这个错误 [英] Why i grt this error
问题描述
DataTable dt = new DataTable();
DateTime time = DateTime.Now.AddHours(10.30);
dt = DAL.Registration_Master.View(time)。 ToString(); //错误
//错误无法将类型''string''隐式转换为''System.Data。 DataTable''
//这是什么解决方案?
即使我将其转换为
dt = Convert.ToDateTime(DAL.Registration_Master.View(time).ToString());
但它仍然给我错误..
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..
推荐答案
您正在尝试将字符串值分配给DataTable。
You are trying to assign String value to DataTable.
dt =Convert.ToDateTime(DAL.Registration_Master.View(time).ToString());
您不能直接将字符串值分配给DataTable。
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
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
--Sj
这篇关于为什么我会发现这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!