Data Gridview内容根据组合框值的选择。 [英] Data Gridview contents as per the selection of Combo box value.

查看:90
本文介绍了Data Gridview内容根据组合框值的选择。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据组合框值的选择显示Data Gridview内容。



例如:我有供应商组合框,根据我选择的值从它来看,供应商的相关信息将显示在.net中的Data Gridview控件中。

I want to show Data Gridview contents as per the selection of Combo box value.

E.g: I have Supplier combo box , as per the value I am selecting from it related information of supplier will display in Data Gridview control in .net.

推荐答案

这归结为获取组合框的值并将其放入适当的SQL中SELECT语句将数据库信息转换为数据表。你只是将DGV DataSource属性设置为返回的数据表。
This comes down to getting the value of the combobox and putting it into an appropriate SQL SELECT statement to get the database information into a datatable. THen you just set the DGV DataSource property to the datatable returned.


我已经尝试过以下代码,但是系统给出了我对sql查询的错误对象引用未设置为对象的实例



Dim ds作为新数据集



Str =选择p.PO_no,p。日期,来自PO_Header的s.Sup_name p,Supplier_Master s其中p.Sup_no =''& cmbItemName.SelectedValue.ToString()&''



Dim da As New SqlDataAdapter(str,SetCon())

da.Fill(ds,New)

< pre lang =vb> DataGridView1。 DataSource = ds.Tables(0).DefaultView< / pre>



我的代码中是否有任何问题。
I already tried following code but system give me Error on sql query Object reference not set to an instance of an object

Dim ds As New DataSet

Str = Select p.PO_no,p.Date,s.Sup_name from PO_Header p, Supplier_Master s Where p.Sup_no = ''" & cmbItemName.SelectedValue.ToString() & "''"

Dim da As New SqlDataAdapter(str, SetCon())
da.Fill(ds, "New")
<pre lang="vb">DataGridView1.DataSource =ds.Tables(0).DefaultView</pre>

Is there is any thing wrong in my code.


1.创建子

1. Create sub
Private Sub refresh_data()
  Dim Ds as new dataset
  Dim Query as String = "Select * from Supplier_master where Supplier_ID = '" & cmb_supplierID.text & "'"
  Dim SQL_Adapter as new SqlDataAdapter(Query,Connection)

  SQL_Adapter.fill(Ds)
  DataGridView1.DataSource = Ds.Tables(0)
End Sub





2.在事件组合框中选择更改



2. in event combo box selected change

call refresh_data()


这篇关于Data Gridview内容根据组合框值的选择。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆