从MySQL数据VB.NET在datagridview中填写特定的列 [英] Fill specific columns in datagridview from MySQL data VB.NET

查看:682
本文介绍了从MySQL数据VB.NET在datagridview中填写特定的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个具有4列数据的Datagridview EJ:

  ID,Name,Quantity,other 

但是我想从MySQL EJ填写这3列:

  item_id,item_name,item_quantity 

我尝试了这段代码: / p>

 使用cn作为新的MySqlConnection(server = 10.10.2.1; userid = root; password = gf-159753; database = quick_admon )
cn.Open()

Dim da As New MySqlDataAdapter(select * from qa_items,cn)
'DataTable
Dim dt As New DataTable

'llenar el DataTable
da.Fill(dt)

'enlazar el DataTable al BindingSource
list_items.DataSource = dt

使用list_items
.MultiSelect = False
.SelectionMode = DataGridViewSelectionMode.FullRowSelect

.DataSource = list_items.DataSource
结束

结束使用

但这会创建新的列,不会写对现有的,花了一段时间寻找解决方案,但只能找到这样的方法。

解决方案

您未能将查询中的列绑定到数据网格视图列中。为此,


1。)右键单击 DataGridView。

2.)弹出菜单出现,单击编辑列

3.)绑定每列( ID 通过从
分别输入字段名称(item_id,item_name,item_quantity),在中查询您的查询,
数量其他 DataPropertyName 属性(,以便
不会像您所做的那样创建另一个列)


你完成了!



更新



设置 DataPropertyName

  list_items.Columns(ID)DataPropertyName =item_id

或假设ID是您的第一列:

  list_items.Columns(0).DataPropertyName =item_id


I have created a Datagridview with 4 Columns, EJ:

ID, Name, Quantity, other

But i want to fill these 3 Columns from MySQL EJ:

item_id, item_name, item_quantity

I tryed this code:

    Using cn As New MySqlConnection("server=10.10.2.1;userid=root;password=gf-159753;database=quick_admon")
        cn.Open()

        Dim da As New MySqlDataAdapter("SELECT * from qa_items", cn)
        ' DataTable  
        Dim dt As New DataTable

        ' llenar el DataTable  
        da.Fill(dt)

        ' enlazar el DataTable al BindingSource  
        list_items.DataSource = dt

        With list_items 
            .MultiSelect = False 
            .SelectionMode = DataGridViewSelectionMode.FullRowSelect

            .DataSource = list_items.DataSource
        End With

    End Using

but this creates new columns and does not write to the existing, took a while looking for a solution but only find methods like this.

解决方案

You failed to bind the columns from your query into your datagrid view columns. To do this,

1.) Right Click DataGridView.
2.) A Popup Menu appears and Click Edit Columns
3.) Bind each columns (ID, Name, Quantity, other) by typing the field name (item_id, item_name, item_quantity) respectively from your query in the DataPropertyName property (so that it will not create another column like you did).

And you're done!

UPDATE

Setting DataPropertyName Propgramatically

list_items.Columns("ID").DataPropertyName = "item_id"

or Assuming that ID is your first column:

list_items.Columns(0).DataPropertyName = "item_id"

这篇关于从MySQL数据VB.NET在datagridview中填写特定的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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