Я пытаюсь сохранить данные сетки данных в таблицу базы данных.
SP_InsertBookHeader
работает нормально, но при выполнении SP_InsertBookDetail
появляется ошибка:
Процедура илив функции SP_InsertBookDetail указано слишком много аргументов
Я проверил процедуру и код C #;оба параметра одинаковы.
Book.cs:
private void addRecord()
{
try
{
string btnClick = CusMsgBox.showBox("SAVE", "Do you want to save record?");
if (btnClick == "1")
{
var bookInfo = new BookInformation();
bookInfo.BookID = txtBookID.Text;
bookInfo.Copies = int.Parse(txtCopies.Text);
bookInfo.Date = DateTime.Parse(dtpDate.Value.ToString());
var bookList = new List<BookInformation>();
foreach (DataGridViewRow items in dgvBook.Rows)
{
var bookDetailInfo = new BookInformation();
bookDetailInfo.BookID = txtBookID.Text;
bookDetailInfo.ISBN = items.Cells["ISBN"].Value.ToString();
bookDetailInfo.Name = items.Cells["Name"].Value.ToString();
bookDetailInfo.Description = items.Cells["Description"].Value.ToString();
bookDetailInfo.PublishDate = DateTime.Parse(items.Cells["Publish Date"].Value.ToString());
bookDetailInfo.Language = items.Cells["Language"].Value.ToString();
bookDetailInfo.AuthorID = items.Cells["Author"].Value.ToString();
bookDetailInfo.Category = items.Cells["Category"].Value.ToString();
bookDetailInfo.Edition = int.Parse(items.Cells["Edition"].Value.ToString());
bookDetailInfo.Price = decimal.Parse(items.Cells["Price"].Value.ToString());
bookList.Add(bookDetailInfo);
}
var bookService = new BookService();
int line = bookService.insertBook(bookInfo, bookList);
if (line > 0)
{
clearRecord();
clearBookRecord();
viewBookID();
viewBookRecord();
CusNotifi.showSuccess("Data Inserted Succesfully!");
}
else
{
CusNotifi.showError("Data Insert Failed!");
}
}
else
{
CusMsgBox cmb = new CusMsgBox();
cmb.Dispose();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
BookService.cs:
public int insertBook(BookInformation bookInfo, List<BookInformation> bookList)
{
var bookData = new BookData();
return bookData.addRecord(bookInfo, bookList);
}
BookData.cs
public int addRecord(BookInformation bookInfo, List<BookInformation> bookList)
{
try
{
cmd = new SqlCommand("SP_InsertBookHeader", dbcon.ActiveCon());
sda = new SqlDataAdapter(cmd);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
sda.SelectCommand.Parameters.Add("@BookID", SqlDbType.VarChar).Value = bookInfo.BookID;
sda.SelectCommand.Parameters.Add("@Copies", SqlDbType.Int).Value = bookInfo.Copies;
sda.SelectCommand.Parameters.Add("@Date", SqlDbType.DateTime).Value = bookInfo.Date;
var cmdDetail = new SqlCommand("SP_InsertBookDetail", dbcon.ActiveCon());
var sdaDetail = new SqlDataAdapter(cmdDetail);
sdaDetail.SelectCommand.CommandType = CommandType.StoredProcedure;
foreach (BookInformation items in bookList)
{
sdaDetail.SelectCommand.Parameters.Add("@BookID", SqlDbType.VarChar).Value = items.BookID;
sdaDetail.SelectCommand.Parameters.Add("@ISBN", SqlDbType.VarChar).Value = items.ISBN;
sdaDetail.SelectCommand.Parameters.Add("@Name", SqlDbType.VarChar).Value = items.Name;
sdaDetail.SelectCommand.Parameters.Add("@Description", SqlDbType.VarChar).Value = items.Description;
sdaDetail.SelectCommand.Parameters.Add("@PublishDate", SqlDbType.DateTime).Value = items.PublishDate;
sdaDetail.SelectCommand.Parameters.Add("@Language", SqlDbType.VarChar).Value = items.Language;
sdaDetail.SelectCommand.Parameters.Add("@AuthorID", SqlDbType.VarChar).Value = items.AuthorID;
sdaDetail.SelectCommand.Parameters.Add("@Category", SqlDbType.VarChar).Value = items.Category;
sdaDetail.SelectCommand.Parameters.Add("@Edition", SqlDbType.Int).Value = items.Edition;
sdaDetail.SelectCommand.Parameters.Add("@Price", SqlDbType.Decimal).Value = items.Price;
}
int line = cmd.ExecuteNonQuery();
int line1 = cmdDetail.ExecuteNonQuery();
return line;
}
catch
{
throw;
}
finally
{
cmd.Dispose();
dbcon.CloseCon();
}
}
Процедура:
ALTER PROCEDURE [dbo].[SP_InsertBookDetail]
@BookID VARCHAR(20),
@ISBN VARCHAR(50),
@Name VARCHAR(100),
@Description VARCHAR(10),
@PublishDate DATETIME,
@Language VARCHAR(20),
@AuthorID VARCHAR(20),
@Category VARCHAR(20),
@Edition INT,
@Price DECIMAL(18, 2)
AS
BEGIN
INSERT INTO Book_Detail(BookID, ISBN, Name, Description, PublishDate, Language, AuthorID, Category, Edition, Price)
VALUES (@BookID, @ISBN, @Name, @Description, @PublishDate, @Language, @AuthorID, @Category, @Edition, @Price)
END