C# 更新数据库';使用EF的WCF服务中的s表
我想在wcf web服务中更新我的数据库表。但我有两个错误。首先,我无法将字符串更改为datetime。我发送了“1/1/1991”,但我得到了错误。其次,我无法更新我的表。我怎样才能修好它C# 更新数据库';使用EF的WCF服务中的s表,c#,wcf,entity-framework,C#,Wcf,Entity Framework,我想在wcf web服务中更新我的数据库表。但我有两个错误。首先,我无法将字符串更改为datetime。我发送了“1/1/1991”,但我得到了错误。其次,我无法更新我的表。我怎样才能修好它 myentities db = new myentities(); public bool EditPerson(int uid,string _name,string bdate,string adr,string cty,string email,string tel,string pass)
myentities db = new myentities();
public bool EditPerson(int uid,string _name,string bdate,string adr,string cty,string email,string tel,string pass)
{
DateTime myDate = DateTime.ParseExact(bdate, "yyyy-MM-dd",null); //Error
var person = db.Person.FirstOrDefault(x => x.pID == uid);
if (person != null)
{
Person pt = new Person();
pt.pName = _name;
pt.birthDate = myDate;
pt.adress = adr;
pt.city = cty;
pt.email = email;
pt.tel = int.Parse(tel);
db.Entry(person).CurrentValues.SetValues(pt);
db.SaveChanges(); //Error
return true;
}
return false;
}
错误:由于内部错误,客户端无法处理请求。
Server stack trace:
location: System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
location: System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
location: System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
location: System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
location: System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
location: System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
location: System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
location: IService.EditPerson(Int32 uid, String _name, String bdate, String adr, String cty, String email, String tel, String pass)
location: ServiceClient.EditPerson(Int32 uid, String _name, String bdate, String adr, String cty, String email, String tel, String pass)
从
将日期和时间的指定字符串表示形式转换为其
使用指定格式和特定区域性的DateTime等效项
格式信息字符串表示形式的格式必须匹配
指定的格式完全相同。
Server stack trace:
location: System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
location: System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
location: System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
location: System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
location: System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
location: System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
location: System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
location: IService.EditPerson(Int32 uid, String _name, String bdate, String adr, String cty, String email, String tel, String pass)
location: ServiceClient.EditPerson(Int32 uid, String _name, String bdate, String adr, String cty, String email, String tel, String pass)
在你的情况下,他们不是。如果字符串是1/1/1991
,则需要使用d/M/yyyy
(我假设第一个是day)格式
您可能需要使用,因为它有一个特殊的含义,就是用当前的文化日期分隔符替换我。当使用null作为参数时,此方法使用。如果您当前的区域性线程将/
作为一个线程,则可以使用null
DateTime myDate = DateTime.ParseExact(bdate, "d/M/yyyy",
CultureInfo.InvariantCulture);
我不能对您的更新错误说任何话,因为我对Entity Framework不太熟悉。“我遇到了错误”绝对没有用。什么错误?哪里“我不能更新我的表”也是如此-为什么不能?我不能更新,
db.SaveChanges()
会出错。真的吗?错误?我已经写过:如果您不告诉我们您遇到了什么错误,我们将无法帮助您。错误:由于内部错误,客户端无法处理请求。