本文介绍了我想通过使用gri视图填充来查看sql数据(已选中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个名为GRIDVIEWITEM_BILL的数据网格视图,有六个单元格(列) 1(项目)(组合框) 2(数量)(文本框) 3(金额)(文本框) 4(折扣)(文本框) 5(税)(文本框) 6(总计)(文本框) i希望从sql填写表格的负载 我的代码 public void billgridfill() { int i = 0 ; string str = 选择项目,数量来自比尔的金额,金额,折扣,税金,总额,其中Opd_No喜欢' + TBBOX_OPDNO_BILL.Text + '而F_Name如' + TBBOX_PNAME_BILL.Text + '; SqlCommand cmd = new SqlCommand(str,Con_Class.con); c.con_open(); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { GRIDVIEWITEM_BILL.Rows [i] .Cells [ 0 ]。值= sdr [ 项目]。ToString( ); GRIDVIEWITEM_BILL.Rows [i] .Cells [ 1 ]。值= sdr [ Qty]。ToString(); GRIDVIEWITEM_BILL.Rows [i] .Cells [ 2 ]。值= sdr [ Amount]。ToString(); GRIDVIEWITEM_BILL.Rows [i] .Cells [ 3 ]。值= sdr [ Discount]。ToString(); GRIDVIEWITEM_BILL.Rows [i] .Cells [ 4 ]。值= sdr [ Tax]。ToString(); GRIDVIEWITEM_BILL.Rows [i] .Cells [ 5 ]。值= sdr [ Total]。ToString(); GRIDVIEWITEM_BILL.Rows.Add(row); i ++; } sdr.Close(); c.con_close(); } 解决方案 看看这个:如何填充datagridview-from-database [ ^ ] 使用这个: 如果(sdr.HasRows) { GRIDVIEWITEM_BILL.DataSource = dr; GRIDVIEWITEM_BILL.DataBind(); } 或 SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); da = new SqlDataAdapter(sql,ConnectionString); da.Fill(dt); GRIDVIEWITEM_BILL.DataSource = dr; GRIDVIEWITEM_BILL.DataBind(); i have a datagridview with name GRIDVIEWITEM_BILL and have six cell(column)1(Item)(combobox)2(Qty)(textbox)3(Amount)(textbox)4(Discount)(textbox)5(Tax)(textbox)6(Total)(textbox)i want to fill on load of form from sqlmy codepublic void billgridfill() { int i = 0; string str = "select Item,Qty,Amount,Discount,Tax,Total from Bill where Opd_No like'" + TBBOX_OPDNO_BILL.Text + "' And F_Name like'" + TBBOX_PNAME_BILL.Text + "'"; SqlCommand cmd = new SqlCommand(str, Con_Class.con); c.con_open(); SqlDataReader sdr = cmd.ExecuteReader(); while(sdr.Read()) { GRIDVIEWITEM_BILL.Rows[i].Cells[0].Value = sdr["Item"].ToString(); GRIDVIEWITEM_BILL.Rows[i].Cells[1].Value = sdr["Qty"].ToString(); GRIDVIEWITEM_BILL.Rows[i].Cells[2].Value = sdr["Amount"].ToString(); GRIDVIEWITEM_BILL.Rows[i].Cells[3].Value = sdr["Discount"].ToString(); GRIDVIEWITEM_BILL.Rows[i].Cells[4].Value = sdr["Tax"].ToString(); GRIDVIEWITEM_BILL.Rows[i].Cells[5].Value = sdr["Total"].ToString(); GRIDVIEWITEM_BILL.Rows.Add(row); i++; } sdr.Close(); c.con_close(); } 解决方案 Check this out: how-to-fill-datagridview-from-database[^]Use this:if(sdr.HasRows){ GRIDVIEWITEM_BILL.DataSource = dr; GRIDVIEWITEM_BILL.DataBind();}ORSqlDataAdapter da = new SqlDataAdapter();DataTable dt = new DataTable();da = new SqlDataAdapter(sql,ConnectionString);da.Fill(dt);GRIDVIEWITEM_BILL.DataSource = dr;GRIDVIEWITEM_BILL.DataBind(); 这篇关于我想通过使用gri视图填充来查看sql数据(已选中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 07:50