首页 > 解决方案 > 将数据从数据网格传递到表单并将其插入数据库

问题描述

此按钮将数据传递给名为 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 发送到数据库,但没有数据保存到数据库。只有 Datepickers 保存到数据库,因为它们与从数据网格传递到此表单的数据无关。

    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();

    }

标签: c#mysql

解决方案


推荐阅读