By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,084 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,084 IT Pros & Developers. It's quick & easy.

Batch update to table from datagrid

P: n/a
I use DatagridTableStyle to display data from table
WF_Carrier_FreightChart. USers than can add/delete/edit rows in the
Datagrid.
Since the Datagrid's datasource "dCarrierFreight" is just a copy/view of the
table (dataset dFreight.tables(0) ), I need to update the original table to
reflect multiple changes in the Datagrid.

Your help is greatly appreciated.

Bill

-------------
Private Function showFreightDetail(ByVal rowID As Integer) As Integer
Dim dSQL As String

Dim dr As DataRow

Dim dvRow As DataRowView

dr = dMain.Tables(0).Rows(rowID)

'txtBolID.Refresh()

txtTest.Text = dr.Item("CarrierName")

dSQL = "SELECT CarrierID, FreightLinkID, Mile_From, Mile_To, WF_GasFreight,
WF_DslFreight, "

dSQL += " JACO_GasFreight, JACO_DslFreight FROM WF_Carrier_FreightChart "

dSQL += " WHERE carrierID = " & "'" & Trim(dr.Item("Carrierid")) & "' "

dSQL += " ORDER By CarrierID, Mile_From, Mile_to "

Try

DataGrid2.Enabled = True

Dim iType As Integer = 1

Dim iSort As Integer

dCarrierFreight = New DataSet("mpCarrier")

Dim tFreight As DataTable

tFreight = New DataTable("dpFreightTable")

Dim cRowID As DataColumn

cRowID = New DataColumn("rowID")

Dim cCarrierID As DataColumn

cCarrierID = New DataColumn("CarrierID")

Dim cMileFrom As DataColumn

cMileFrom = New DataColumn("MileFrom")

Dim cMileTo As DataColumn

cMileTo = New DataColumn("MileTo")

Dim cWFGas As DataColumn

cWFGas = New DataColumn("WFGas")

Dim cWFDsl As DataColumn

cWFDsl = New DataColumn("WFDsl")

Dim cJAGas As DataColumn

cJAGas = New DataColumn("JAGas")

Dim cJADsl As DataColumn

cJADsl = New DataColumn("JADsl")



tFreight.Columns.Add(cRowID)

tFreight.Columns.Add(cCarrierID)

tFreight.Columns.Add(cMileFrom)

tFreight.Columns.Add(cMileTo)

tFreight.Columns.Add(cWFGas)

tFreight.Columns.Add(cWFDsl)

tFreight.Columns.Add(cJAGas)

tFreight.Columns.Add(cjaDsl)

dCarrierFreight.Tables.Add(tFreight)

dFreight = MAPPOINTDataBoss.dWFIRecView(dSQL)

If dFreight.Tables(0).Rows.Count = 0 Then

Beep()

Call DisplayStatus("No records found! Nothing to display.", "red")

Else

End If

Dim dFreightRow, dCarrierFreightRow As DataRow

For Each dFreightRow In dFreight.Tables(0).Rows

dCarrierFreightRow = tFreight.NewRow

dCarrierFreightRow("rowID") = iType.ToString

dCarrierFreightRow("CarrierID") = dFreightRow.Item("CarrierID")

dCarrierFreightRow("Milefrom") = dFreightRow.Item("Mile_From")

dCarrierFreightRow("Mileto") = dFreightRow.Item("Mile_To")

dCarrierFreightRow("WFGas") = dFreightRow.Item("WF_GasFreight")

dCarrierFreightRow("WFDsl") = dFreightRow.Item("WF_DslFreight")

dCarrierFreightRow("JAGas") = dFreightRow.Item("JACO_GasFreight")

dCarrierFreightRow("JADsl") = dFreightRow.Item("JACO_DslFreight")

tFreight.Rows.Add(dCarrierFreightRow)

Next

' Datagrid table style setup

Dim ts2 As DataGridTableStyle

ts2 = New DataGridTableStyle

ts2.MappingName = "dpFreightTable"

ts2.AlternatingBackColor = Color.Aqua

ts2.AllowSorting = False

Dim txtCol As DataGridTextBoxColumn

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "CarrierID"

txtCol.HeaderText = "CarrierID"

txtCol.ReadOnly = True

txtCol.Width = 40

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "MileFrom"

txtCol.HeaderText = "From"

txtCol.Width = 50

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "MileTo"

txtCol.HeaderText = "To"

txtCol.Width = 50

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "WFGas"

txtCol.HeaderText = "WF Gas"

txtCol.Width = 60

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "WFDsl"

txtCol.HeaderText = "WF Dsl"

txtCol.Width = 60

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "JAGas"

txtCol.HeaderText = "Jaco Gas"

txtCol.Width = 60

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "JADsl"

txtCol.HeaderText = "Jaco Dsl"

txtCol.Width = 60

ts2.GridColumnStyles.Add(txtCol)

DataGrid2.TableStyles.Clear()

DataGrid2.TableStyles.Add(ts2)

Me.DataGrid2.DataSource = dCarrierFreight

Me.DataGrid2.DataMember = "dpFreighttable"

Catch ex As Exception

Catch ex As SqlException

End Try

End Function
Jan 26 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Bill,

A view is not copy
a
Dim a as datatable = myDataTable is not a copy,

It are both other references to the same table

So how do you copy your table.

Cor

"Bill nguyen" <bi*****************@jaco.com> schreef in bericht
news:e4**************@TK2MSFTNGP12.phx.gbl...
I use DatagridTableStyle to display data from table
WF_Carrier_FreightChart. USers than can add/delete/edit rows in the
Datagrid.
Since the Datagrid's datasource "dCarrierFreight" is just a copy/view of
the table (dataset dFreight.tables(0) ), I need to update the original
table to reflect multiple changes in the Datagrid.

Your help is greatly appreciated.

Bill

-------------
Private Function showFreightDetail(ByVal rowID As Integer) As Integer
Dim dSQL As String

Dim dr As DataRow

Dim dvRow As DataRowView

dr = dMain.Tables(0).Rows(rowID)

'txtBolID.Refresh()

txtTest.Text = dr.Item("CarrierName")

dSQL = "SELECT CarrierID, FreightLinkID, Mile_From, Mile_To,
WF_GasFreight, WF_DslFreight, "

dSQL += " JACO_GasFreight, JACO_DslFreight FROM WF_Carrier_FreightChart "

dSQL += " WHERE carrierID = " & "'" & Trim(dr.Item("Carrierid")) & "' "

dSQL += " ORDER By CarrierID, Mile_From, Mile_to "

Try

DataGrid2.Enabled = True

Dim iType As Integer = 1

Dim iSort As Integer

dCarrierFreight = New DataSet("mpCarrier")

Dim tFreight As DataTable

tFreight = New DataTable("dpFreightTable")

Dim cRowID As DataColumn

cRowID = New DataColumn("rowID")

Dim cCarrierID As DataColumn

cCarrierID = New DataColumn("CarrierID")

Dim cMileFrom As DataColumn

cMileFrom = New DataColumn("MileFrom")

Dim cMileTo As DataColumn

cMileTo = New DataColumn("MileTo")

Dim cWFGas As DataColumn

cWFGas = New DataColumn("WFGas")

Dim cWFDsl As DataColumn

cWFDsl = New DataColumn("WFDsl")

Dim cJAGas As DataColumn

cJAGas = New DataColumn("JAGas")

Dim cJADsl As DataColumn

cJADsl = New DataColumn("JADsl")



tFreight.Columns.Add(cRowID)

tFreight.Columns.Add(cCarrierID)

tFreight.Columns.Add(cMileFrom)

tFreight.Columns.Add(cMileTo)

tFreight.Columns.Add(cWFGas)

tFreight.Columns.Add(cWFDsl)

tFreight.Columns.Add(cJAGas)

tFreight.Columns.Add(cjaDsl)

dCarrierFreight.Tables.Add(tFreight)

dFreight = MAPPOINTDataBoss.dWFIRecView(dSQL)

If dFreight.Tables(0).Rows.Count = 0 Then

Beep()

Call DisplayStatus("No records found! Nothing to display.", "red")

Else

End If

Dim dFreightRow, dCarrierFreightRow As DataRow

For Each dFreightRow In dFreight.Tables(0).Rows

dCarrierFreightRow = tFreight.NewRow

dCarrierFreightRow("rowID") = iType.ToString

dCarrierFreightRow("CarrierID") = dFreightRow.Item("CarrierID")

dCarrierFreightRow("Milefrom") = dFreightRow.Item("Mile_From")

dCarrierFreightRow("Mileto") = dFreightRow.Item("Mile_To")

dCarrierFreightRow("WFGas") = dFreightRow.Item("WF_GasFreight")

dCarrierFreightRow("WFDsl") = dFreightRow.Item("WF_DslFreight")

dCarrierFreightRow("JAGas") = dFreightRow.Item("JACO_GasFreight")

dCarrierFreightRow("JADsl") = dFreightRow.Item("JACO_DslFreight")

tFreight.Rows.Add(dCarrierFreightRow)

Next

' Datagrid table style setup

Dim ts2 As DataGridTableStyle

ts2 = New DataGridTableStyle

ts2.MappingName = "dpFreightTable"

ts2.AlternatingBackColor = Color.Aqua

ts2.AllowSorting = False

Dim txtCol As DataGridTextBoxColumn

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "CarrierID"

txtCol.HeaderText = "CarrierID"

txtCol.ReadOnly = True

txtCol.Width = 40

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "MileFrom"

txtCol.HeaderText = "From"

txtCol.Width = 50

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "MileTo"

txtCol.HeaderText = "To"

txtCol.Width = 50

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "WFGas"

txtCol.HeaderText = "WF Gas"

txtCol.Width = 60

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "WFDsl"

txtCol.HeaderText = "WF Dsl"

txtCol.Width = 60

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "JAGas"

txtCol.HeaderText = "Jaco Gas"

txtCol.Width = 60

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "JADsl"

txtCol.HeaderText = "Jaco Dsl"

txtCol.Width = 60

ts2.GridColumnStyles.Add(txtCol)

DataGrid2.TableStyles.Clear()

DataGrid2.TableStyles.Add(ts2)

Me.DataGrid2.DataSource = dCarrierFreight

Me.DataGrid2.DataMember = "dpFreighttable"

Catch ex As Exception

Catch ex As SqlException

End Try

End Function

Jan 26 '06 #2

P: n/a
Cor;
Providing the problem, can you helo show me a solution?

Thanks
Bill
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:OP**************@TK2MSFTNGP11.phx.gbl...
Bill,

A view is not copy
a
Dim a as datatable = myDataTable is not a copy,

It are both other references to the same table

So how do you copy your table.

Cor

"Bill nguyen" <bi*****************@jaco.com> schreef in bericht
news:e4**************@TK2MSFTNGP12.phx.gbl...
I use DatagridTableStyle to display data from table
WF_Carrier_FreightChart. USers than can add/delete/edit rows in the
Datagrid.
Since the Datagrid's datasource "dCarrierFreight" is just a copy/view of
the table (dataset dFreight.tables(0) ), I need to update the original
table to reflect multiple changes in the Datagrid.

Your help is greatly appreciated.

Bill

-------------
Private Function showFreightDetail(ByVal rowID As Integer) As Integer
Dim dSQL As String

Dim dr As DataRow

Dim dvRow As DataRowView

dr = dMain.Tables(0).Rows(rowID)

'txtBolID.Refresh()

txtTest.Text = dr.Item("CarrierName")

dSQL = "SELECT CarrierID, FreightLinkID, Mile_From, Mile_To,
WF_GasFreight, WF_DslFreight, "

dSQL += " JACO_GasFreight, JACO_DslFreight FROM WF_Carrier_FreightChart "

dSQL += " WHERE carrierID = " & "'" & Trim(dr.Item("Carrierid")) & "' "

dSQL += " ORDER By CarrierID, Mile_From, Mile_to "

Try

DataGrid2.Enabled = True

Dim iType As Integer = 1

Dim iSort As Integer

dCarrierFreight = New DataSet("mpCarrier")

Dim tFreight As DataTable

tFreight = New DataTable("dpFreightTable")

Dim cRowID As DataColumn

cRowID = New DataColumn("rowID")

Dim cCarrierID As DataColumn

cCarrierID = New DataColumn("CarrierID")

Dim cMileFrom As DataColumn

cMileFrom = New DataColumn("MileFrom")

Dim cMileTo As DataColumn

cMileTo = New DataColumn("MileTo")

Dim cWFGas As DataColumn

cWFGas = New DataColumn("WFGas")

Dim cWFDsl As DataColumn

cWFDsl = New DataColumn("WFDsl")

Dim cJAGas As DataColumn

cJAGas = New DataColumn("JAGas")

Dim cJADsl As DataColumn

cJADsl = New DataColumn("JADsl")



tFreight.Columns.Add(cRowID)

tFreight.Columns.Add(cCarrierID)

tFreight.Columns.Add(cMileFrom)

tFreight.Columns.Add(cMileTo)

tFreight.Columns.Add(cWFGas)

tFreight.Columns.Add(cWFDsl)

tFreight.Columns.Add(cJAGas)

tFreight.Columns.Add(cjaDsl)

dCarrierFreight.Tables.Add(tFreight)

dFreight = MAPPOINTDataBoss.dWFIRecView(dSQL)

If dFreight.Tables(0).Rows.Count = 0 Then

Beep()

Call DisplayStatus("No records found! Nothing to display.", "red")

Else

End If

Dim dFreightRow, dCarrierFreightRow As DataRow

For Each dFreightRow In dFreight.Tables(0).Rows

dCarrierFreightRow = tFreight.NewRow

dCarrierFreightRow("rowID") = iType.ToString

dCarrierFreightRow("CarrierID") = dFreightRow.Item("CarrierID")

dCarrierFreightRow("Milefrom") = dFreightRow.Item("Mile_From")

dCarrierFreightRow("Mileto") = dFreightRow.Item("Mile_To")

dCarrierFreightRow("WFGas") = dFreightRow.Item("WF_GasFreight")

dCarrierFreightRow("WFDsl") = dFreightRow.Item("WF_DslFreight")

dCarrierFreightRow("JAGas") = dFreightRow.Item("JACO_GasFreight")

dCarrierFreightRow("JADsl") = dFreightRow.Item("JACO_DslFreight")

tFreight.Rows.Add(dCarrierFreightRow)

Next

' Datagrid table style setup

Dim ts2 As DataGridTableStyle

ts2 = New DataGridTableStyle

ts2.MappingName = "dpFreightTable"

ts2.AlternatingBackColor = Color.Aqua

ts2.AllowSorting = False

Dim txtCol As DataGridTextBoxColumn

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "CarrierID"

txtCol.HeaderText = "CarrierID"

txtCol.ReadOnly = True

txtCol.Width = 40

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "MileFrom"

txtCol.HeaderText = "From"

txtCol.Width = 50

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "MileTo"

txtCol.HeaderText = "To"

txtCol.Width = 50

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "WFGas"

txtCol.HeaderText = "WF Gas"

txtCol.Width = 60

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "WFDsl"

txtCol.HeaderText = "WF Dsl"

txtCol.Width = 60

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "JAGas"

txtCol.HeaderText = "Jaco Gas"

txtCol.Width = 60

ts2.GridColumnStyles.Add(txtCol)

txtCol = New DataGridTextBoxColumn

txtCol.MappingName = "JADsl"

txtCol.HeaderText = "Jaco Dsl"

txtCol.Width = 60

ts2.GridColumnStyles.Add(txtCol)

DataGrid2.TableStyles.Clear()

DataGrid2.TableStyles.Add(ts2)

Me.DataGrid2.DataSource = dCarrierFreight

Me.DataGrid2.DataMember = "dpFreighttable"

Catch ex As Exception

Catch ex As SqlException

End Try

End Function


Jan 26 '06 #3

P: n/a
Bill,

In the way you tell it, than your datasource is the original table and you
can use that to update, however it can as well be.

mynewtable as datatable = myoldtable.copy

Than you can use mynewtable to update and than you have to decide if you
fill the myoldtable again or merge the mynewtable in it.

It is not an abc sample, so again, tell us first how you copy that table.

Cor
Jan 26 '06 #4

P: n/a
In the original post I included the codes.

Bill
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:eB**************@TK2MSFTNGP14.phx.gbl...
Bill,

In the way you tell it, than your datasource is the original table and you
can use that to update, however it can as well be.

mynewtable as datatable = myoldtable.copy

Than you can use mynewtable to update and than you have to decide if you
fill the myoldtable again or merge the mynewtable in it.

It is not an abc sample, so again, tell us first how you copy that table.

Cor

Jan 26 '06 #5

P: n/a
Bill,

You are using a shallow copy, what is very hard to manage. It is a copy of
the references pointing to the original objects.

For a DataTable something without sence. Why are you doing that, while the
datatable has so many other posibilities.

Cor
Jan 27 '06 #6

P: n/a
What's the best / better way to handle batch update in this case, please?

Thanks

Bill

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:uZ**************@TK2MSFTNGP10.phx.gbl...
Bill,

You are using a shallow copy, what is very hard to manage. It is a copy of
the references pointing to the original objects.

For a DataTable something without sence. Why are you doing that, while the
datatable has so many other posibilities.

Cor

Jan 28 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.