[英]Cannot implicitly convert type 'System.DateTime' to 'string'
I am trying to output an excel file and part of it puts the value of createddate from a table called outofstock the line is currently putting a 0 我正在尝试输出一个excel文件,并且它的一部分从一个叫做outofstock的表中放入createddate的值,该行当前放置0
If I run this SQL it shows everything fine 如果我运行此SQL,它将显示一切正常
select wo.email, wo.productid, wo.variantid, p.NAME pname,
p.SKU psku, wo.createdon, pc.CategoryID, c.Name
from woeosemails wo
join Product p with (nolock) on p.ProductID = wo.productid
left join ProductCategory as pc (nolock) on p.ProductID=pc.ProductID
left join Category as c (nolock) on pc.CategoryID=c.CategoryID
order by wo.createdon, wo.email, wo.productid
The problem lies with this line in the aspx.cs file generating the output 问题在于aspx.cs文件中的此行生成输出
createdon = DB.RSFieldDateTime(NotifyReader, "createdon");
I don't know what type (int, string etc) to place before. 我不知道之前要放置什么类型(整数,字符串等)。 Within the SQL table the DataType is datetime but using this does not seem to work. 在SQL表中,数据类型为datetime,但是使用它似乎无效。
Any thoughts? 有什么想法吗?
string email = DB.RSField(NotifyReader, "email");
int productid = DB.RSFieldInt(NotifyReader, "productid");
int variantid = DB.RSFieldInt(NotifyReader, "variantid");
string createdon = DB.RSFieldDateTime(NotifyReader, "createdon");
string psku = DB.RSField(NotifyReader, "psku");
string pname = DB.RSField(NotifyReader, "pname");
string cname = DB.RSField(NotifyReader, "cname");
Well, the error is clear: you cannot cast a DateTime to string automatically. 好吧,错误很明显:您不能将DateTime强制转换为字符串。
You should use 你应该用
DateTime createdon = DB.RSFieldDateTime(NotifyReader, "createdon");
or 要么
string createdon = DB.RSFieldDateTime(NotifyReader, "createdon").ToString();
Also remember that you can use specific formats to represent your date in a string (see http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx ) 还要记住,您可以使用特定的格式以字符串形式表示日期(请参阅http://msdn.microsoft.com/zh-cn/library/8kb3ddd4(v=vs.110).aspx )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.