它工作正常并插入我的第一个表值
SqlCommand command = new SqlCommand("INSERT INTO Author (LastName, FirstName, MiddleName,BirthDate)VALUES(@LastName, @FirstName, @MiddleName,@BirthDate);SELECT SCOPE_IDENTITY()", _connection);
command.Parameters.AddWithValue("@LastName", LastNameTextBox.Text);
command.Parameters.AddWithValue("@FirstName", FirstNameTextBox.Text);
command.Parameters.AddWithValue("@MiddleName", MiddleNameTextBox.Text);
command.Parameters.AddWithValue("@BirthDate", BirthDateTextBox.Text);
string authoriD = command.ExecuteScalar().ToString();
在这里我有问题,无法解决
SqlCommand commandB = new SqlCommand("INSERT INTO Book(AuthorID,Book,Genre,Pages)VALUES(@AuthorID,@Book,@Genre,@Pages)", _connection);
commandB.Parameters.AddWithValue("@AuthorID", authoriD);
for (int i = 0; i < AddBooks.BookTextBoxValue.Count; i++)
{
commandB.Parameters.AddWithValue("@Book", AddBooks.BookTextBoxValue[i]);
}
foreach (string itemgenre in AddBooks.GenreTextBoxValue)
{
commandB.Parameters.AddWithValue("@Genre", itemgenre);
}
foreach (string itempages in AddBooks.PagesTextBoxValue)
{
commandB.Parameters.AddWithValue("@Pages", itempages);
}
commandB.ExecuteNonQuery();