正常に動作し、最初のテーブル値に挿入します
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();