将数据从datagrid传递到窗体并将其插入数据库

np8igboo  于 2021-06-17  发布在  Mysql
关注(0)|答案(0)|浏览(259)

此按钮将数据传递到一个名为check\u out的窗体,再传递到另一个名为borrowbook的窗体

private void RentButton_Click(object sender, EventArgs e)
    {
        BorrowBook borrow = new BorrowBook();

        borrow.BookIDtextBox.Text = CheckOutDataGridView.CurrentRow.Cells[0].Value.ToString();
        borrow.AFirstnameTextBox.Text = CheckOutDataGridView.CurrentRow.Cells[2].Value.ToString();
        borrow.ConditionTextBox.Text = CheckOutDataGridView.CurrentRow.Cells[3].Value.ToString();
        borrow.BookNTextBox.Text = CheckOutDataGridView.CurrentRow.Cells[1].Value.ToString();
        borrow.EdTextBox.Text = CheckOutDataGridView.CurrentRow.Cells[0].Value.ToString();

        borrow.PriceTextBox.Text = CheckOutDataGridView.CurrentRow.Cells[6].Value.ToString();

        borrow.Show();

    }

此按钮将数据从借阅簿发送到数据库,但没有数据保存到数据库。只有datepicker保存到数据库,因为它们与从datagrid传递到此表单的数据无关。

private void Rentbutton_Click(object sender, EventArgs e)
    {
        Book_Class book_ = new Book_Class();

        if (book_.SaveRental(book_))
        {
            book_.BookID = int.Parse(BookIDtextBox.Text);
            book_.price = double.Parse(PriceTextBox.Text);
            book_.school_ID = int.Parse(RenteeIDtextBox.Text);
            book_.rentDate = RentedDateTimePicker.Value;
            book_.returnDate = ReturnDateTimePicker.Value;

            MessageBox.Show("Record saved");
        }
        else
        { MessageBox.Show(this, "Oops, something went wrong, please try again or contact administrator", "ERROR"); }

        this.Close();

    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题