代碼中的最後插入我的存儲過程插入喜歡這個獲取背後
insert into Profile_Master(FirstName,LastName,Dob,Gender,MobileNo,Country,State,EmailId,Password)
values
(@FirstName,@LastName,@Dob,@Gender,@MobileNo,@Country,@State,@EmailId,@Password)
set @id=SCOPE_IDENTITY()
return
end
我想在代碼中的最後插入記錄的背後,如何捕捉到的價值?
pid = cmd1.Parameters.Add("@id", System.Data.SqlDbType.Int);
pid.Direction = System.Data.ParameterDirection.Output;
int res = Convert.ToInt32(pid.Value);
HttpContext.Current.Session["value"] = res.ToString();
這裏我得到res爲0,所以值沒有得到更新在第二頁。
這裏有一個偉大的博客條目:http://www.mikesdotnetting.com/Article/54/Getting-the-identity-of-the-most-recently-added-record –
你在調用'cm1.ExecuteNonQuery ()'在讀取'pid'值之前? –
我在讀取pid值後調用cmd1.ExecuteNonQuery()。 –