如何将datagridview值从一个表单1传递到表单2以插入数据库 [英] How to pass the datagridview values from one form 1 to form 2 for insertion of database
本文介绍了如何将datagridview值从一个表单1传递到表单2以插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将数据格式视图值从表单1传递到表单2以插入数据库以进行销售点项目。任何人请给我合适的解决方案
我尝试过:
How to pass the datagridview values from form 1 to form 2 to insert into database for Point of sale Project. Anyone Please give me the proper solution
What I have tried:
private void salesPayment_Click(object sender, EventArgs e)
{
if (metroGrid1.Rows.Count == 0)
{
MessageBox.Show("No Products Added for Sales..");
}
else
{
SalesPay popup = new SalesPay();
popup.NetTotal = netPrice.Text;
popup.Netgst = gstPrice.Text;
DialogResult dialogResult = popup.ShowDialog();
}
void dataGridColumns()
{
for (int i = 0; i <= metroGrid1.Rows.Count - 1; i++)
{
string prodName = metroGrid1.Rows[i].Cells[0].Value.ToString();
string prodRetailPrice = metroGrid1.Rows[i].Cells[1].Value.ToString();
string prodQuantity = metroGrid1.Rows[i].Cells[2].Value.ToString();
string prodTotalPrice = metroGrid1.Rows[i].Cells[3].Value.ToString();
}
}
推荐答案
您可以使用辅助类来存储DataGridView行值,然后将它们存储在a 列表<> 。然后可以将此列表序列化为XML或传递给另一种形式。
以下是一个示例:低维护XML设置机制 [ ^ ]
更好的方法是使用 BindingSource ,请参阅这篇优秀文章:详细的数据绑定教程 [ ^ ]
您也可以使用活动,参见:在Windows窗体之间传递数据 [ ^ ]
You could use a helper class to store DataGridView row values and then store these in a List<>. This list can then be serialized to XML or passed to another form.
Here is an example: A Low Maintenance XML Settings Mechanism[^]
A better way to do things however is to use a BindingSource, see this excellent article: A Detailed Data Binding Tutorial[^]
You can also use events, see: Passing Data between Windows Forms[^]
我也有这个问题,它解决了我的问题
参见@OriginalGriff Sir Article。
传输信息两种形式之间[^]
Also i have that problem and it solved my problem
See @OriginalGriff Sir Article.
Transferring information between two forms[^]
这篇关于如何将datagridview值从一个表单1传递到表单2以插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文