When I add a record to my database, I retrieve the auto generated ID key from the table. I need to place the ID into the Textbox to use later on in my code. Here is my code and it is giving me this error:
Input string was not in a correct format
Here is my code:
// Insert the record by executing the command
numRowsAdded = command.ExecuteNonQuery();
// Use @@IDENTITY to work out the primary key of
// the new row and display it
command.CommandText = "SELECT @@IDENTITY";
id = Convert.ToInt32(command.ExecuteScalar());
id = Convert.ToInt32(lessonIDTextbox.Text);