c# - 将数据从数据网格传递到表单并将其插入数据库
问题描述
此按钮将数据传递给名为 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();
}
解决方案
推荐阅读
- reactjs - React:如何将状态传播到封闭的父级
- python - 为什么 isinstance 不能将 io.BytesIO 识别为 io.IOBase 的子类?
- javascript - discord.js 变量计数
- angular - 在 ng build --prod "./node_modules/ng2-pdf-viewer/fesm5/ng2-pdf-viewer.js" 时出现错误
- vba - 按组和条目自动增加编号
- xamarin.android - 在移动到 xamarin.android 中的主应用程序之前显示登录页面
- python - 来自excel列Python的字典
- c# - 我可以在不打包应用程序的情况下使用 UWP api 连接蓝牙设备吗?
- python - 使用 uvicorn 运行时,fastapi 找不到模型定义
- django - 如何在 Django 中使用 call_command() 在特定数据库上运行迁移?