當我將記錄添加到數據庫時,我從表中檢索自動生成的ID密鑰。我需要將ID放入文本框以便稍後在我的代碼中使用。這裏是我的代碼,它是給我這個錯誤:在文本框控件中添加Int值
Input string was not in a correct format
這裏是我的代碼:
// 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);