Вопрос

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

If I run this SQL it shows everything fine

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

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.

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.
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)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top