I have an access data base where i want to add a row in a table. but I want to get the id(colum name -> id) back.
this is the code i use to register a new group:
int id;
internal static void agregarGrupo(int grado, char grupo, String escuela, int maestro)
{
try
{
comand.Connection = conection;
comand.CommandText =
"INSERT INTO Grupos " +
"(grado, grupo, escuela, maestro) " +
"VALUES(" + grado + ", '" + grupo + "' , '" + escuela + "', " + maestro + ")";
conection.Open();
id = comand.ExecuteScalar();
}
finally
{
conection.Close();
}
}
what am I doing wrong? how can I get the id of the new row without making a new query asking for the bigest id in the table?