我正在制作相册。所以,我想要一张照片属于某个用户。我如何获得用户ID?
var com = new SqlCommand("Insert into Photos (Photo, DatePublished, UserId)" +
"values (@Photo, @DatePublished, @UserId)", con);
com.Parameters.AddWithValue("@Photo", pic);
com.Parameters.AddWithValue("@DatePublished", DateTime.Today);
com.Parameters.AddWithValue("@UserId", //what should be written here?);
con.Open();
com.ExecuteNonQuery();
lblStatus.Text = "Image Uploaded Sucessfully";
或者你能指出一些其他方式来做这种归属吗?谢谢。
答案 0 :(得分:0)
希望您的用户首先登录:)
假设你这样做了,当你做SELECT以检查他们的凭据时,你应该在内存中存储他们的ID。只需检索该值并将其用于此查询。
//Global state is a made up static class of course
com.Parameters.AddWithValue("@UserId", GlobalState.CurrentUserId);