|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Batch update to table from datagridWF_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 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 Show quoteHide quote "Bill nguyen" <billn_nospam_please@jaco.com> schreef in bericht news:e4E2EUoIGHA.1424@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 > > Cor;
Providing the problem, can you helo show me a solution? Thanks Bill Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:OPyG$npIGHA.1388@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" <billn_nospam_please@jaco.com> schreef in bericht > news:e4E2EUoIGHA.1424@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 >> >> > > 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 In the original post I included the codes.
Bill Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:eB2j45pIGHA.2036@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 > 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 What's the best / better way to handle batch update in this case, please?
Thanks Bill Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:uZB8hewIGHA.2928@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 >
Create Access ODBC DSN ?
Syntax not accepted on my version of VS why ?. Best way to do a connection-oriented Send/Receive. need ideas - caching strategy RS 2005: Use a Custom Class as DataSource? beta 3 what is the MyApplication.vshost.exe? New 2 dotnet but Im a vb6 programmer remoting in net FileSystemWatcher question |
|||||||||||||||||||||||