我只想将出生日期保存到SQL数据库中,但每次获得新的异常时,数据库字段类型都是datetime.这是我的代码
usinfo.BirthDate = DateTime.ParseExact(txtDOB.Text.ToString(), "MM/dd/yyyy", CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud) 在以下代码中返回一个列表:
public List<Customer> GeAllCust()
{
var results = db.Customers
.Select(x => new { x.CustName, x.CustEmail, x.CustAddress, x.CustContactNo })
.ToList()
return results;
}
Run Code Online (Sandbox Code Playgroud)
我收到错误报告C#无法转换列表:
错误:无法将类型隐式转换
System.Collections.Generic.List<AnonymousType#1>
为System.Collections.Generic.List<WebApplication2.Customer>
这是为什么?
这是一个屏幕截图,显示Visual Studio在错误的工具提示中提供的一些其他信息:
返回一些列而不是整个表是正确的方法....?
public object GeAllCust()
{
var results = db.Customers.Select(x => new { x.CustName, x.CustEmail, x.CustAddress, x.CustContactNo }).ToList();
return results;
}
Run Code Online (Sandbox Code Playgroud) Web表单上有两个提交按钮,需要字段验证,我想如果我点击第一个提交按钮,它不会检查第二个提交.意思是我只希望只有第一个文本框必需的验证必须有效吗?我应该怎么做才能在多个提交按钮上分离验证更多细节,包括快照.
这里有三个表Service_Orders,Project_Services和Company.Service Order和CompanyID在3个表之间存在内部联接.我希望下面的查询使用C#或Vb.net转换为使用Lambda Express的实体框架.
select top 10 * from [Service_Orders] a,[Project_Services] b,[Company] c
where a.so_no = b.service_order and c.companyId = b.compid
Run Code Online (Sandbox Code Playgroud) public class Connection
{
public static string GetConecction()
{
return ConfigurationManager.ConnectionStrings["DCAssetEntities"].ConnectionString;
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个"连接"类来配置我的Web与实体框架模型实体
public class ConnectionDAL
{
private DCAssetEntities db;
public ConnectionDAL()
{
db = new DCAssetEntities(Connection.GetConecction());
}
}
Run Code Online (Sandbox Code Playgroud)
然后我在"ConnectionDAL"类构造函数中初始化我的数据库,它在Visusal Studio 2010中工作得很好,但在因访问工作室2012中显示错误"DC_Asset_Maintenance.DAL.DCAssetEntities'不包含带有1个参数的构造函数"