使用Model edmx将数据插入数据库

时间:2017-10-04 06:37:26

标签: c# database model

我在visual studio中创建数据库作为基于服务的数据库之后我创建表格我试图通过从数据库中选择更新模型将其连接到Model .edmx 现在当我向Model .edmx插入数据时,它没有将它插入数据库如何使用Model和它将数据插入数据库 我正在使用Visual Studio 2010

一些代码:

  private  CoffeeShopDatabaseEntities1 cse = new CoffeeShopDatabaseEntities1();
    private Byte[] bytedata;
    public addproduct()
    {
        InitializeComponent();

        cbocatgrey.DataSource = cse.TblProductType.ToList();
        cbocatgrey.DisplayMember = "Descrption";
        cbocatgrey.ValueMember = "ProductType";
    }

    private void upload_image_Click(object sender, EventArgs e)
    {
        DialogResult dlg = openFileDialog1.ShowDialog();
        if (dlg == DialogResult.OK)
        {
            FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
            bytedata = new Byte[fs.Length];
            fs.Read(bytedata, 0, bytedata.Length);
            fs.Close();
            MemoryStream ms = new MemoryStream(bytedata);
            pload.Image = Image.FromStream(ms);

        }
    }

    private void save_Click(object sender, EventArgs e)
    {
        TblProduct product = new TblProduct();
        product.Descrption = descrptiontxt.Text;
        product.Price = decimal.Parse(pricetxt.Text);
        product.Image = bytedata;
        product.ProductType = (int)cbocatgrey.SelectedValue;
        cse.AddtoTBlProduct(product);
        cse.saveChanges();


    }

0 个答案:

没有答案