处理此请求时发生错误。 [英] An error occurred while processing this request.

查看:463
本文介绍了处理此请求时发生错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎收到了一般错误消息:处理此请求时出错。





这是在这个代码行



I seem to be getting the generic error message: An error occurred while processing this request.


It is occurring on this line of code

context.SaveChanges();





我正在使用DataServices插入到SQL数据库中。



这是Order表数据库的SQL代码,这是我正在尝试插入数据:





I'm using DataServices to insert into an SQL database.

This is the SQL code for the database for the Order table, which is where I'm trying to insert the data:

CREATE TABLE [Order]
(
	OrderNo INT IDENTITY(1,1) NOT NULL,
	CustomerNo INT NOT NULL,
	OrderDateTime DATETIME NOT NULL,
	DeliveryAddress1 VARCHAR(50) NOT NULL,
	DeliveryAddress2 VARCHAR(50),
	TownCity VARCHAR(30) NOT NULL,
	PostCode VARCHAR(8) NOT NULL,
	DeliveryCharge MONEY,
	PaymentMethod VARCHAR(30) NOT NULL,
	[Status] VARCHAR(10) NOT NULL CHECK([Status] IN ('Pending', 'Completed', 'Cancelled')),
	DispatchDate DATETIME,
	CONSTRAINT [PK_OrderNo] PRIMARY KEY (OrderNo),
	CONSTRAINT [FK_OrderCustomerNo] FOREIGN KEY (CustomerNo) REFERENCES Customer(CustomerNo)
)





这是代码整个班级,原谅我的混乱,一旦代码工作,我倾向于清理。





This is the code for the entire class, excuse my messiness, I tend to clean up once the code works.

public OrderItemWindow()
        {
            InitializeComponent();
        }

        private iShopEntities context;

        private Uri svcUri = new Uri("http://localhost:29875/iShop.svc");

        System.Windows.Data.CollectionViewSource productsViewSource;
        System.Windows.Data.CollectionViewSource productOptionsViewSource;
        System.Windows.Data.CollectionViewSource ordersViewSource;


        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {


            productsViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("productsViewSource")));
            productOptionsViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("productOptionsViewSource")));
            ordersViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("ordersViewSource")));

            context = new iShopEntities(svcUri);
            context.IgnoreMissingProperties = true;


            var query = context.CreateQuery<Product>("GetProductDetails").AddQueryOption("ProductID", GlobalVariables.productID);

            var query2 = context.CreateQuery<ProductOption>("GetProductOptionDetails").AddQueryOption("OptionID", GlobalVariables.optionID);

            productsViewSource.Source = new DataServiceCollection<Product>(query);
            productOptionsViewSource.Source = new DataServiceCollection<ProductOption>(query2);


            ordersViewSource.Source = new DataServiceCollection<Order>(context);

            ListCollectionView orderList = (ListCollectionView)ordersViewSource.View;
            orderList.AddNewItem(new Order());

            customerNoTextBox.Text = GlobalVariables.customerNo.ToString();
            deliveryChargeLabel.Content = extraDeliveryChargeLabel.Content;
            orderDateTimeDatePicker.SelectedDate = DateTime.Now;
            statusTextBox.Text = "Pending";
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void buyButton_Click(object sender, RoutedEventArgs e)
        {
            context.SaveChanges();
        }
    }

推荐答案

这篇关于处理此请求时发生错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆