【发布时间】:2011-04-23 08:27:47
【问题描述】:
当我向我的数据库添加一条记录时,我会从表中检索自动生成的 ID 键。我需要将 ID 放入文本框中,以便稍后在我的代码中使用。这是我的代码,它给了我这个错误:
输入的字符串格式不正确
这是我的代码:
// 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);
【问题讨论】: