我只是为了更新与分类表和产品表有关的表格而感到mad。
I have these tables
product product_id
product_name
product_description
product_price
product_image
category category_id
catgory_name
category_desc
我这样做是为了更新表格......利用实体框架......。
private void btnSave_Click(object sender, EventArgs e)
{
if (lblHiddenmode.Text == "Edit")
{
using (var dbcontext = new TsgEntities())
{
pictureBox1.Enabled = true;
pictureBox1.Visible = true;
Image image = pictureBox1.Image;
byte[] bit = null;
bit = imageToByteArray(image);
product1 pd = new product1();
string category = cbcategorytypes.Text;
string categorydesc = tbCategoryDescription.Text;
var c = new category { category_Name = category, category_Description = categorydesc };
pd.product_Name = tbProductName.Text;
decimal price = Convert.ToDecimal(tbProductPrice.Text);
pd.product_Price = price;
pd.product_Description = tbProductdescription.Text;
pd.product_Image = bit;
pd.category = c;
dbcontext.SaveChanges();
this.Close();
}
}
}
NOTE:我正在更新产品名称,产品名称为4,类别为:id=4。
但它将在本发言中显示pd. category = c;。 i got 产品_id = “0”和“0”类
am i doing wrong when updating the table with category table .. is there any problem with update statement