我有兩個表,Projects
和ProjectImages
。我想從第二個表中獲取image_id。這是我當前的代碼:我想在兩個表中更新一個按鈕button1_click
SqlConnection con = new SqlConnection(「Data Source = .; Initial Catalog = Waves; Integrated Security = true;」);
SqlCommand com = new SqlCommand("Update_Project", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@ProjectID",Label1.Text);
com.Parameters.AddWithValue("@ProjectName",txtName.Text);
com.Parameters.AddWithValue("@VideoUrl", txtName.Text);
com.Parameters.AddWithValue("@Notes", txtName.Text);
com.Parameters.AddWithValue("@Date",DateTime.Now.Date);
WavesEntities wee = new WavesEntities();
var query = from p in wee.Project_Images
select p.img_Id;
SqlCommand com1 = new SqlCommand("UpdateProjectImages", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@img_id", query.AsEnumerable());
com.Parameters.AddWithValue("@img_path", con);
con.Open();
com.ExecuteNonQuery();
con.Close();
錯誤:
No mapping exists from object type System.Data.Objects.ObjectQuery`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] to a known managed provider native type.
你可以在一個存儲過程中做兩個更新嗎? – Tim 2014-09-26 15:49:57
我無法獲取img_id參數 – 2014-09-26 15:55:07
'com.Parameters.AddWithValue(「@ img_id」,query.AsEnumerable());'是問題所在,我不太確定你期望這樣做,但你正在嘗試以IEnumerable'作爲SQL參數。 –
2014-09-26 15:57:36