开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜