开发者

How can I populate a texbox with a date retireved from SQL server? I get the message, " cannot explicitly convert form stirng to system datetime

开发者 https://www.devze.com 2023-03-11 10:09 出处:网络
How can I populate a texbox with a date retireved from SQL server?I 开发者_如何学Goget the message

How can I populate a texbox with a date retireved from SQL server? I 开发者_如何学Goget the message

cannot explicitly convert form string to system datetime.

I am trying this:

string getEffectiveDate = from v in dt.vw_AMLI_Participants
                          where v.SSN == getSSNNow && v.CustomerID == 56
                          select v.EffectiveDate.ToString;


There seems to be a couple of issues with your query. As stated by someone else, you are missing the parenthesis from your ToString() method call. The second issue is that the query will return IQueryable<string> and you are trying to assign it to a string. If you are running under the assumption that your query will always return a single result, try the following:

string getEffectiveDate = (from v in dt.vw_AMLI_Participants
                      where v.SSN == getSSNNow && v.CustomerID == 56
                      select v.EffectiveDate.ToString()).Single();

If that is still giving you problems (which it may because the Linq provider may not know how to interprerate v.EffectiveDate.ToString()), then try the following:

string getEffectiveDate = (from v in dt.vw_AMLI_Participants
                      where v.SSN == getSSNNow && v.CustomerID == 56
                      select v.EffectiveDate).Single().ToString();


You might need to write ToString() (notice you left out the parenthesis).


Just remove the toString:

string getEffectiveDate = from v in dt.vw_AMLI_Participants 
    where v.SSN == getSSNNow && v.CustomerID == 56 select v.EffectiveDate;
0

精彩评论

暂无评论...
验证码 换一张
取 消