내 응용 프로그램이 서버에 파일을 업로드하고 DB에 저장하고 각각에 대한 제거 링크 (GridView
에 바인딩 나는 같은 마지막 ID마다 무엇입니까 LAST_VALUE 사용하는 경우 행)
는
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 열의 마지막 값이 아닌 마지막 자동 인식 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();