我的應用程序上傳的服務器上的文件並將其保存到數據庫,並與刪除鏈接,每個綁定到(GridView
行)
如果我使用LAST_VALUE每次我收到相同的最後一個ID
SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["DSN"]);
SqlCommand ident = new SqlCommand("select LAST_VALUE where name = 'Id' and object_id = object_id('image')", connection);
connection.Open();
id = Convert.ToInt32(ident.ExecuteScalar());
_fileName = fileName;
_fullFileName = _outputPath + (id + 1).ToString() + prefix + Path.GetFileName(_fileName);
_fs = new FileStream(_fullFileName, FileMode.Create);
我的問題是,磨片n我正在使用如下所示的MAX(Id)
,直到有人刪除最後一行或MAX行時我失去了我的身份,這一切都很好 - 這就是爲什麼我想要獲得最後一個自動增加的身份而不是最後一個ID列的值
SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["DSN"]);
SqlCommand ident = new SqlCommand("SELECT MAX(Id) from image", connection);
connection.Open();
SqlDataReader result = ident.ExecuteReader();
result.Read();
object obValue = result.GetValue(0);
id = Convert.ToInt32(obValue.ToString());
connection.Close();