ADO.NET 服务更新错误
我对 ADO.NET 服务有一个非常简单的练习:将产品列表放入列表框中,当列表框中的选择发生更改时,在两个文本框中显示 UnitPrice 和 UnitInStock。 然后更改文本框中的数据并保存更改。
以下是客户端的所有代码:
namespace TestApp
{
public partial class Form1 : Form
{
NorthwindDataContext ctx = new NorthwindDataContext(new Uri("http://localhost:3540/Northwind.svc/"));
public Form1()
{
InitializeComponent();
var q = from p in ctx.Products
select p;
listBox1.DataSource = q.ToList();
listBox1.DisplayMember = "ProductName";
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var p = listBox1.SelectedItem as Product;
textBox1.Text = p.UnitPrice.ToString();
textBox2.Text = p.UnitsInStock.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
var p = listBox1.SelectedItem as Product;
p.UnitPrice = Decimal.Parse(textBox1.Text);
p.UnitsInStock = short.Parse(textBox2.Text);
try
{
//ctx.AttachTo("Products", p);
//ctx.BeginSaveChanges();
ctx.UpdateObject(p);
ctx.SaveChanges(SaveChangesOptions.None);
}
catch (Exception ex)
{
label3.Text = ex.Message;
}
}
}
}
ADO.NET 服务很好,其权限设置为:
config.SetEntitySetAccessRule("*", EntitySetRights.All);
当我点击保存按钮时,我收到错误消息: ex.Message =“处理此请求时发生错误。”
不知道为什么。请帮忙。
I have a very simple exercise on ADO.NET Service: Put the list of Product in a list box, when selection changed in the list box, display UnitPrice and UnitInStock in two textboxes.
Then change the data in textboxes and save the changes.
Here is all code for at client side:
namespace TestApp
{
public partial class Form1 : Form
{
NorthwindDataContext ctx = new NorthwindDataContext(new Uri("http://localhost:3540/Northwind.svc/"));
public Form1()
{
InitializeComponent();
var q = from p in ctx.Products
select p;
listBox1.DataSource = q.ToList();
listBox1.DisplayMember = "ProductName";
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var p = listBox1.SelectedItem as Product;
textBox1.Text = p.UnitPrice.ToString();
textBox2.Text = p.UnitsInStock.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
var p = listBox1.SelectedItem as Product;
p.UnitPrice = Decimal.Parse(textBox1.Text);
p.UnitsInStock = short.Parse(textBox2.Text);
try
{
//ctx.AttachTo("Products", p);
//ctx.BeginSaveChanges();
ctx.UpdateObject(p);
ctx.SaveChanges(SaveChangesOptions.None);
}
catch (Exception ex)
{
label3.Text = ex.Message;
}
}
}
}
The ADO.NET Service is fine and its permission set as:
config.SetEntitySetAccessRule("*", EntitySetRights.All);
When I hit the save button, I got error message as:
ex.Message = "An error occurred while processing this request."
Not sure why. please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请在您的服务上打开 UserVerboseErrors
,这将有助于覆盖方法 handleException
完成后让我们知道错误是什么。
please on your service turn on the UserVerboseErrors
And it would be helpful to override the method handleexception
After you have done that let us know what the error is.
这是针对 Silverlight 客户端还是 WinForms 的?为什么从使用 BeginSaveChanges() 切换到 SaveChanges()?
Is this for a Silverlight client or WinForms? Why did you switch from using BeginSaveChanges() to SaveChanges()?