mardi 4 août 2015

c# sqlite retrieve last inserted row (Char ID)

I'm trying to retrieve the last inserted ID, my problem is my ID is CHAR Type, it is like ABC0001. I have tried some function like below, but i still cant get the ID. can anyone tell me what's wrong with my code, or i using the wrong function?

string sql = "SELECT ID FROM Customer ORDER BY name LIMIT 1";
// select Max(ID) FROM Customer
// last_insert_row
// last()

setConnection();
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
sql_cmd.CommandText = sql;       
string lastID = Convert.ToString(sql_cmd.ExecuteScalar());
sql_con.Close();

Aucun commentaire:

Enregistrer un commentaire