将数据从数据网格传递到表单并将其插入数据库

时间:2018-11-26 23:59:04

标签: c# mysql

此按钮将数据传递给名为Check_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();



    }

此按钮将数据从BorrowBook发送到数据库,但是没有数据保存到数据库。只有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();

    }

0 个答案:

没有答案