【发布时间】:2011-08-19 09:42:50
【问题描述】:
我有个表叫
product
product_id
product_Name
product_Price
product_Description
product_image
category_id
another table category
category_id
category_name
我有一个带有文本框的新表单
txtprodname
txtproddescrip
txtproductprice
picturebox1
txtcategoryname
我正在尝试使用以下代码将新产品添加到产品表中
我正在使用实体框架..
public byte[] imageToByteArray(System.Drawing.Image image)
{
MemoryStream ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return ms.ToArray();
}
private void btnSave_Click(object sender, EventArgs e)
{
Image image = pictureBox1.Image;
byte[] bit = null;
bit = imageToByteArray(image);
product pd = new product();
pd.product_Name = txtprodname.Text;
decimal price = Convert.ToDecimal(txtproductprice.Text);
pd.product_Price = price;
pd.product_Description = txtproddescrip.Text;
pd.product_Image = bit;
tsgentity.AddToproducts(pd);
tsgentity.SaveChanges();
this.Close();
}
我正在尝试将新产品添加到产品表中……但我不知道如何使用 linq 将类别名称添加到类别表中……
如何将类别名称添加到类别表并使用我输入的类别名称更新产品表...
如何使用输入的这个名称以及添加到产品表中的新产品更新产品表中的类别 ID
任何人都可以帮助解决这个问题......
我正在使用 winforms .....和 c# 语言
这是我的实体图......
【问题讨论】:
标签: c# winforms linq entity-framework linq-to-entities