如何在基于服务的数据库中插入数据? [英] How to insert data in service-based database?

查看:95
本文介绍了如何在基于服务的数据库中插入数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法使用C#Express中基于服务的数据库将数据插入到我的表中。我正在使用Entity-Framework,我有以下代码。但是当我刷新数据库资源管理器中的表时,没有找到数据。

I can't seem to insert data into my table using a service-based database in C# Express. I am using Entity-Framework and I have the following code. But when I refresh the table in the database explorer, no data is found.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace CoffeeShopProject
{
    public partial class AddProduct : Form
    {
        private CoffeeShopDatabaseEntities cse = new CoffeeShopDatabaseEntities();
        private Byte[] byteBLOBData;

        public AddProduct()
        {
            InitializeComponent();
            cboCategory.DataSource = cse.tblProductTypes;
            cboCategory.DisplayMember = "Description";
            cboCategory.ValueMember = "ProductType";
        }

        private void btnUpload_Click(object sender, EventArgs e)
        {
            DialogResult result = openFileDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                FileStream fsBLOBFile = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
                byteBLOBData = new Byte[fsBLOBFile.Length];
                fsBLOBFile.Read(byteBLOBData, 0, byteBLOBData.Length);
                fsBLOBFile.Close();
                MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
                pxbImage.Image = Image.FromStream(stmBLOBData);
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            tblProduct products = new tblProduct();
            products.Description = txtDescription.Text;
            products.Price = int.Parse(txtPrice.Text);
            products.Image = byteBLOBData;
            products.ProductType = (int)cboCategory.SelectedValue;
            cse.SaveChanges();
            MessageBox.Show("Record Saved!");
        }
    }
}





我尝试了什么:



我还没有尝试过任何东西。只是这个。我自昨晚以来一直在网上寻找解决方案,但无济于事我找不到。



What I have tried:

I have not tried anything yet. Just this. I have been searching online for solutions since last night but to no avail I have found none.

推荐答案

Windows窗体应用程序是每次构建时重新生成bin文件夹。如果您每次都在visual studio中运行,请重新生成bin文件夹。还将您保存的数据存入数据库到bin文件夹下,但是您在项目文件夹中查找数据库!基于服务的数据库可以清楚地复制到每个构建的bin文件夹。
The windows forms applications are regenerate bin folder every build. If do you every run in visual studio, regenerate bin folder. Also your saved data into database to under bin folder, but you looking to database in project folder! Service based databases are copy to bin folder every build as clearly.


这篇关于如何在基于服务的数据库中插入数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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