如何用从SQL server退休的日期填充texbox?我收到消息,“;无法显式地将表单stiring转换为系统日期时间

本文关键字:日期 系统 时间 转换 表单 stiring 消息 server SQL 何用 填充 | 更新日期: 2023-09-27 17:58:31

如何用从SQL server退休的日期填充texbox?我收到信息

无法将表单字符串显式转换为系统日期时间。

我正在尝试这个:

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

如何用从SQL server退休的日期填充texbox?我收到消息,“;无法显式地将表单stiring转换为系统日期时间

您的查询似乎有几个问题。正如其他人所说,ToString()方法调用中缺少括号。第二个问题是查询将返回IQueryable<string>,而您正试图将其分配给string。如果您在假设查询总是返回一个结果的情况下运行,请尝试以下操作:

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

如果这仍然给你带来问题(可能是因为Linq提供商可能不知道如何解释v.EffectiveDate.ToString()),那么尝试以下操作:

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

您可能需要编写ToString()(请注意,您遗漏了括号)。

只需删除toString:

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