Mon application télécharge un fichier sur le serveur et enregistrez-le db et le lier à (GridView
avec lien de suppression pour chaque rangée)
Si je last_value je reçois le même dernier identifiant chaque fois que
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);
Mon problème est que whe n J'utilisais MAX(Id)
comme ci-dessous, tout allait bien jusqu'à ce que je perds mon identité quand quelqu'un supprime la dernière rangée ou la rangée MAX - c'est pourquoi j'essaye d'obtenir la dernière identité auto-incrémentée et non la dernière valeur de la colonne 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();