I have tried using the SELECT query to get the last id from the database, i.e. SELECT LAST_INSERT_id FROM studentdetails but it is not working for me.
I really need help!
Please what query can I use to get the last id from the database?
string me = dtba.ConnectionString();
SqlConnection connection = new SqlConnection(me);
string selectquery = "SELECT LAST_INSERT_id FROM studentdetails";
SqlCommand selectcmd = new SqlCommand(selectquery, connection);
selectcmd.Parameters.AddWithValue("@id", registrationNo.Text);
try
{
    connection.Open();
    SqlDataReader reader = selectcmd.ExecuteReader();
    if (reader.Read())
    {                    
        registrationNo.Text = reader["id"].ToString();
    }
    if (registrationNo.Text == "")
    {
        MessageBox.Show("SORRY ID HAS NOT BEEN READ");
    }
    else
    {
        MessageBox.Show("REGISTRATION NUMBER IS CORRECT");
    }
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
finally
{
    connection.Close();
}
 
     
    