0

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.

1
  • Do you really want the server IP, userid, and password to be shown to every viewer? Commented Apr 8, 2016 at 20:23

1 Answer 1

6

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"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.