我在从gridview的订单表中存储值和存储过程的结果时遇到问题

时间:2019-01-04 21:11:02

标签: c# asp.net entity-framework

我正在asp.net中创建一个电子商务购物车页面。在结帐按钮上,我想通过存储过程将用户详细信息保存到数据库中,并从存储过程的返回结果中获取ID。从网格视图来看,我正在获取产品详细信息并将其存储到订单表中。

客户详细信息已成功保存。但是我无法将网格视图中的值保存到订单表中。

using (var db = new ModelDatabaseEntities())
{
    var query = db.GetSelectedItemsDetail(productlist);
    GV.DataSource = query;
    GV.DataBind();
}

protected void btnSignUp_Click(object sender, EventArgs e)
{
    CustomerId = createCustomer();

    for (int count = 0; count < GV.Rows.Count; count++)
    {
        var Id = GV.Rows[count].Cells[0].Text;
        var Name = GV.Rows[0].Cells[1].Text;
       // var Price = Convert.ToInt32(GV.Rows[0].Cells[3].Text);
       // var Quantity = Convert.ToInt32(GV.Rows[0].Cells[5].Text);

       // string strDate = DateTime.Today.ToString();
       // DateTime c = DateTime.Parse(strDate);
       using (var db = new ModelDatabaseEntities())
        {
            db.EnterOrder(Convert.ToInt32(Id), CustomerId, 200, 2, "2/3/2014");
            db.SaveChanges();
       }
    }
}

public int createCustomer()
{
    var UserName = txtFirstName.Text + txtLastName.Text;
    var Email = txtEmailAddress.Text;
    var Password = txtPassword.Text;
    var Adress = txtAddress.Text;

    using (var db = new ModelDatabaseEntities())
    {
        CustomerId = Convert.ToInt32(db.Register("asad", "raza", "asad",true,"asad", "121313"));
        db.SaveChanges();
        return CustomerId;
    }
}

0 个答案:

没有答案