如何从数据库获取值到datagridview当前行? [英] How to get value from database to datagridview current row?
本文介绍了如何从数据库获取值到datagridview当前行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想生成gridview当前行中的所有数据。但条件是当我将值id放在datagrid视图单元格中时,它会自动填充该行吗? (就像在数据网格视图单元格中放置条形码值一样)。
我尝试过的方法:
I want to generate all the data in gridview current row. But the condition is the when i put value id in datagrid view cell it automatic fill that row? (Just like put a barcode value in data grid view cell).
What I have tried:
if (dataGridView1.Rows.Count>1)
{
DataTable dt = new DataTable();
//fetching the data form the item code or barcode
// MessageBox.Show(dataGridView1.Rows[0].Cells["calitem_name"].Value.ToString());
dt = blsto.getallstockbyname((dataGridView1.CurrentRow.Cells["calbar_code"].Value).ToString());
if (dt.Rows.Count > 0)
{
//get crt price
DataTable dts = blcrt.getpricebycrtvalue(dt.Rows[0]["crt_value"].ToString());
decimal crt_price = Convert.ToDecimal(dts.Rows[0]["crt_price"].ToString());
//
decimal weight = Convert.ToDecimal(dt.Rows[0]["weight"].ToString());
int quantity = Convert.ToInt32(dt.Rows[0]["quantity"].ToString());
decimal making_charge = Convert.ToDecimal(dt.Rows[0]["labour_charge"].ToString());
decimal stone_price = Convert.ToDecimal(dt.Rows[0]["stone_charge"].ToString());
decimal margin_price = Convert.ToDecimal(dt.Rows[0]["margin_price"].ToString());
decimal past_sell_price = Convert.ToDecimal(dt.Rows[0]["sell_price"].ToString());
decimal todaysellprice = Convert.ToDecimal((weight * crt_price) + margin_price + stone_charge + making_charge);
dataGridView1.CurrentRow.Cells["calitem_name"].Value = dt.Rows[0]["item_name"].ToString();
dataGridView1.CurrentRow.Cells["calweight"].Value = dt.Rows[0]["weight"].ToString();
dataGridView1.CurrentRow.Cells["calqty"].Value = dt.Rows[0]["quantity"].ToString();
dataGridView1.CurrentRow.Cells["calrate"].Value = dt.Rows[0]["sell_price"].ToString();
dataGridView1.CurrentRow.Cells["calcrt"].Value = dt.Rows[0]["crt_value"].ToString();
dataGridView1.CurrentRow.Cells["calstoneprice"].Value = dt.Rows[0]["stone_charge"].ToString();
dataGridView1.CurrentRow.Cells["caltotal"].Value = todaysellprice;
}
else
{
lbl_barcode.Text = "Set Barcode Again, Can't find Product";
}
decimal result = 0;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
result += Convert.ToDecimal(row.Cells["caltotal"].Value);
}
txtsubtotal.Text = result.ToString();
}
推荐答案
更改此类代码,
Change code like this,
dataGridView1.Rows[rowindex].Cells["column_name or column_index"].Value = your_value;
这篇关于如何从数据库获取值到datagridview当前行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文