Databinding in Datagrid??

B

Bruce D

I'm new to VB.NET and I think I may have a stupid question. I'm just now
understanding the dataview,datagrid relationship. I have created a dataview
from a MySQL database. I'm doing everything programatically. So, I have
this datagrid on my form which displays the data from my tables...my
question...if I edit a field in the grid, how do I update the database?
Here's a small example of what I'm doing. I'm lost...any help is
appreciated...maybe an article to read?

' first I connect to MySQL and return a datatable
dvFinders = New DataView(dtFinders) ' create dataview
' now I create the columns for my datagrid
Dim objDGTS As New DataGridTableStyle
objDGTS.AlternatingBackColor = Color.Beige
objDGTS.MappingName = "Finders"
' create textbox column
Dim objCol As New DataGridTextBoxColumn
objCol.MappingName = "findernumber"
objCol.HeaderText = " "
objCol.Width = 50
objDGTS.GridColumnStyles.Add(objCol)
DataGrid1.TableStyles.Add(objDGTS)
' then I do the databinding
DataGrid1.SetDataBinding(dvFinders, "")

The grid looks good on the form. I have a save button on the form. I don't
know what to do to update the database if I edit the 'findernumber' on the
grid.

-bruce d
 
K

Ken Tucker [MVP]

Hi,

Call the DataAdapter.Update Method.

Ken
--------------------------
I'm new to VB.NET and I think I may have a stupid question. I'm just now
understanding the dataview,datagrid relationship. I have created a dataview
from a MySQL database. I'm doing everything programatically. So, I have
this datagrid on my form which displays the data from my tables...my
question...if I edit a field in the grid, how do I update the database?
Here's a small example of what I'm doing. I'm lost...any help is
appreciated...maybe an article to read?

' first I connect to MySQL and return a datatable
dvFinders = New DataView(dtFinders) ' create dataview
' now I create the columns for my datagrid
Dim objDGTS As New DataGridTableStyle
objDGTS.AlternatingBackColor = Color.Beige
objDGTS.MappingName = "Finders"
' create textbox column
Dim objCol As New DataGridTextBoxColumn
objCol.MappingName = "findernumber"
objCol.HeaderText = " "
objCol.Width = 50
objDGTS.GridColumnStyles.Add(objCol)
DataGrid1.TableStyles.Add(objDGTS)
' then I do the databinding
DataGrid1.SetDataBinding(dvFinders, "")

The grid looks good on the form. I have a save button on the form. I don't
know what to do to update the database if I edit the 'findernumber' on the
grid.

-bruce d
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top