6
Forum Software Development Programming Languages basic.visual DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 - basic.visual This is a discussion on DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 - basic.visual ; A datagrid, dgrCaseSiteInput, could contain as few rows as 1. Several of the columns are for entry. A cmd button successfully executes a stored procedure to update the database based on those entries. Problem: I don't know how to update ... DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 User Name Password Log in Remember Me? Help What's New? FAQ Calendar Forum Actions Quick Links Advanced Search + Reply to Thread Results 1 to 5 of 5 LinkBack Thread Tools 08-05-2005 07:53 PM DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 A datagrid, dgrCaseSiteInput, could contain as few rows as 1. Several of the columns are for entry. A cmd button successfully executes a stored procedure to update the database based on those entries. Problem: I don't know how to update the table after the user changes a value in an entry column. I don't want to have to depend on the user clicking another record in dgrCaseSiteInput to update the source table. This goal is an attempt to simplify the user interface, and to allow for the possibility that dgrCaseSiteInput might contain only 1 row. Can someone tell me - which Event(s) to use to trap a change, and - what method to use to write the change to the database ... rsCaseSiteFetch.UpdateBatch adAffectAll ? I populate dgrCaseSiteInput using code at the bottom. Thank you for any help. Larry Mehl --------------------------------------------------- Dim conn As New ADODB.Connection Dim rsCaseSiteFetch As New ADODB.Recordset Dim strSQLCaseSiteFetch As String Dim strCaseID As String Set conn = New ADODB.Connection Set rsCaseSiteFetch = New ADODB.Recordset conn.CursorLocation = adUseClient conn.Open "PROVIDER=MSDASQL;dsn=Provisioning;uid=;pwd=;" strCaseID = frmMain.txtCaseID.Text strSQLCaseSiteFetch = _ "SELECT CaseID_s, SiteID_s, HeadEndCount_s, STXInstalledYN_s, " & _ "SiteIDParentSvr_s, SiteIDParentSTX_s, HubCount_s, " & _ "HHPassedPerNode_s, " & _ "SubsDigCount_s , Nodes_Site_s, " & _ "SubsDigCountMfr_s, " & _ "PSUAgg_Svr_s, PSUAgg_STX_s " & _ "FROM CaseSite " & _ "WHERE CaseID_s = '" & strCaseID & "'" rsCaseSiteFetch.Open _ strSQLCaseSiteFetch, _ conn, adOpenStatic, adLockOptimistic Set dgrCaseSiteInput.DataSource = rsCaseSiteFetch #1 Join Date: Posts: Nov 2009 0 Application Development Junior Member Reply With Quote 08-05-2005 10:18 PM Re: DataGrid - how detect a change in any field in 1 row, and thenupdate table? VB6, SQL 2000 L Mehl wrote: #2 Forum DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 2015/05/25 http://objectmix.com/basic-visual/155832-datagrid-how-detect-change-any-field-1-row-then-update-table-vb6-sql-2000-a.html 1 / 6

Using DataGrid VB6

Embed Size (px)

DESCRIPTION

DataGrid - How Detect a Change in Any Field in 1 Row, And Then Update table using VB6 and SQL Server

Citation preview

  • Forum Software Development Programming Languages basic.visualDataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000

    DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 - basic.visualThis is a discussion on DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 - basic.visual ; A datagrid, dgrCaseSiteInput, could contain asfew rows as 1. Several of the columns are for entry. A cmd button successfully executes a stored procedure to update the database based on those entries. Problem: I don'tknow how to update ...

    DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000

    User Name Password Log in Remember Me?

    Help

    What's New?

    FAQ Calendar Forum Actions Quick Links Advanced Search

    + Reply to Thread Results 1 to 5 of 5

    LinkBack Thread Tools

    08-05-2005 07:53 PM

    DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000A datagrid, dgrCaseSiteInput, could contain as few rows as 1. Several of

    the columns are for entry.

    A cmd button successfully executes a stored procedure to update the databasebased on those entries.

    Problem:I don't know how to update the table after the user changes a value in anentry column.

    I don't want to have to depend on the user clicking another record indgrCaseSiteInput to update the source table.This goal is an attempt to simplify the user interface, and to allow for thepossibility that dgrCaseSiteInput might contain only 1 row.

    Can someone tell me- which Event(s) to use to trap a change, and- what method to use to write the change to the database ...rsCaseSiteFetch.UpdateBatch adAffectAll ?

    I populate dgrCaseSiteInput using code at the bottom.

    Thank you for any help.

    Larry Mehl

    ---------------------------------------------------Dim conn As New ADODB.ConnectionDim rsCaseSiteFetch As New ADODB.RecordsetDim strSQLCaseSiteFetch As StringDim strCaseID As String

    Set conn = New ADODB.ConnectionSet rsCaseSiteFetch = New ADODB.Recordset

    conn.CursorLocation = adUseClient

    conn.Open "PROVIDER=MSDASQL;dsn=Provisioning;uid=;pwd=;"

    strCaseID = frmMain.txtCaseID.Text

    strSQLCaseSiteFetch = _"SELECT CaseID_s, SiteID_s, HeadEndCount_s, STXInstalledYN_s, " & _"SiteIDParentSvr_s, SiteIDParentSTX_s, HubCount_s, " & _"HHPassedPerNode_s, " & _"SubsDigCount_s , Nodes_Site_s, " & _"SubsDigCountMfr_s, " & _"PSUAgg_Svr_s, PSUAgg_STX_s " & _"FROM CaseSite " & _"WHERE CaseID_s = '" & strCaseID & "'"

    rsCaseSiteFetch.Open _strSQLCaseSiteFetch, _conn, adOpenStatic, adLockOptimistic

    Set dgrCaseSiteInput.DataSource = rsCaseSiteFetch

    #1

    Join Date:Posts:

    Nov 20090

    Application Development Junior Member

    Reply With Quote

    08-05-2005 10:18 PM

    Re: DataGrid - how detect a change in any field in 1 row, and thenupdate table? VB6, SQL 2000L Mehl wrote:

    #2

    Forum

    DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 2015/05/25

    http://objectmix.com/basic-visual/155832-datagrid-how-detect-change-any-field-1-row-then-update-table-vb6-sql-2000-a.html 1 / 6

  • > A datagrid, dgrCaseSiteInput, could contain as few rows as 1. Several of> the columns are for entry.>> A cmd button successfully executes a stored procedure to update the database> based on those entries.>> Problem:> I don't know how to update the table after the user changes a value in an> entry column.>> I don't want to have to depend on the user clicking another record in> dgrCaseSiteInput to update the source table.> This goal is an attempt to simplify the user interface, and to allow for the> possibility that dgrCaseSiteInput might contain only 1 row.>> Can someone tell me> - which Event(s) to use to trap a change, and

    Keypressed() would seem to be the best bet...

    > - what method to use to write the change to the database ...> rsCaseSiteFetch.UpdateBatch adAffectAll ?>> I populate dgrCaseSiteInput using code at the bottom.

    Ooh, Ick, a data-bound control!

    Seriously, though; can you do single-row updates, ordo all rows get updated even if only one row changes?

    If you want single-row updates, just set the..BackColor property of each cell on the current rowto a different color when a change occurs:

    oldcell=grid.colfor x = 1 to grid.cols - 1grid.col = xgrid.backcolor = vbBluenext xgrid.col=oldcell

    An added benefit is that all rows with changes arenow HIGHLIGHTED, so the user can review things beforethey press 'update'.

    Then, when the user presses 'update', scan the gridrow by row; any row with the 'update' .BackColor getsupdated.

    I mark rows for deletion with a third color.

    'air code - assumes blue background rows get updated,'black backgrounds get deleted...

    for x = 1 to grid.rows-1grid.row=xselect case grid.backcolorcase vbBlue:'UPDATE this row of the table'turn the cells in this row back to normalcase vbBlack:'DELETE this row from the table - and the gridend selectnext x

    HTH

    Reply With Quote

    08-06-2005 12:18 AM

    Re: DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000Randy --

    Thanks for the suggestions.

    Can you tell me more about: 'UPDATE this row of the tableIs the statement to use ... rsCaseSiteFetch.UpdateBatch adAffectAll ?

    I think I had better prepare for multiple-row updates.

    Where do I learn how to set up forms not using data-bound controls?

    I will appreciate any further help.

    Larry

    #3

    DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 2015/05/25

    http://objectmix.com/basic-visual/155832-datagrid-how-detect-change-any-field-1-row-then-update-table-vb6-sql-2000-a.html 2 / 6

  • "Randy Day" wrote in messagenews:[email protected]...> L Mehl wrote:>> > A datagrid, dgrCaseSiteInput, could contain as few rows as 1. Severalof> > the columns are for entry.> >> > A cmd button successfully executes a stored procedure to update thedatabase> > based on those entries.> >> > Problem:> > I don't know how to update the table after the user changes a value inan> > entry column.> >> > I don't want to have to depend on the user clicking another record in> > dgrCaseSiteInput to update the source table.> > This goal is an attempt to simplify the user interface, and to allow forthe> > possibility that dgrCaseSiteInput might contain only 1 row.> >> > Can someone tell me> > - which Event(s) to use to trap a change, and>> Keypressed() would seem to be the best bet...>> > - what method to use to write the change to the database ...> > rsCaseSiteFetch.UpdateBatch adAffectAll ?> >> > I populate dgrCaseSiteInput using code at the bottom.>> Ooh, Ick, a data-bound control!> >>>> Seriously, though; can you do single-row updates, or> do all rows get updated even if only one row changes?>> If you want single-row updates, just set the> .BackColor property of each cell on the current row> to a different color when a change occurs:>> oldcell=grid.col> for x = 1 to grid.cols - 1> grid.col = x> grid.backcolor = vbBlue> next x> grid.col=oldcell>> An added benefit is that all rows with changes are> now HIGHLIGHTED, so the user can review things before> they press 'update'.>> Then, when the user presses 'update', scan the grid> row by row; any row with the 'update' .BackColor gets> updated.>> I mark rows for deletion with a third color.>> 'air code - assumes blue background rows get updated,> 'black backgrounds get deleted...>> for x = 1 to grid.rows-1> grid.row=x> select case grid.backcolor> case vbBlue:> 'UPDATE this row of the table> 'turn the cells in this row back to normal> case vbBlack:> 'DELETE this row from the table - and the grid> end select> next x>>> HTH

    Reply With Quote

    08-06-2005 12:24 PM

    Re: DataGrid - how detect a change in any field in 1 row, and thenupdate table? VB6, SQL 2000L Mehl wrote:> Randy -->> Thanks for the suggestions.

    #4

    DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 2015/05/25

    http://objectmix.com/basic-visual/155832-datagrid-how-detect-change-any-field-1-row-then-update-table-vb6-sql-2000-a.html 3 / 6

  • >> Can you tell me more about: 'UPDATE this row of the table> Is the statement to use ... rsCaseSiteFetch.UpdateBatch adAffectAll ?

    I've never heard of 'updatebatch', soI couldn't say.

    Please ignore any lousy indentation below;I'm trying to avoid word wrap!

    '------------------------dim Rst as ADODB.RecordsetDim Cmd as ADODB.Command

    cmd.activeconnection = Rstcmd.commandtype = adcmdtext

    with rst..open "select * from table1"

    if .recordcount = 0 then'no records returnedelsegrid1.rows = .recordcount.movefirstn = 0do while not .eof'put your data in the grid cell-by-'cell. This allows you to do things'(set cell colors, etc) based on the'incoming field values

    grid1.textmatrix(n,0)= .fields.item(0)grid1.textmatrix(n,1)= iif(.fields.item(1)=true,"Yes","No")grid1.textmatrix(n,2)= .fields.item(2)

    n=n+1.movenextloopend ifend with

    private sub air_code_update()Dim strText as string

    'create a SQL UPDATE string using the specific'data from your grid row. I prefer this method'over the Rst.update method because I control the'actual SQL command being sent to the DB engine

    strText = "Update table1 set field1=" + grid1strtext = strText + " where "

    cmd.commandstring=strTextcmd.executeend sub

    >> I think I had better prepare for multiple-row updates.>> Where do I learn how to set up forms not using data-bound controls?>

    This one doesn't give an example of updating an existingrecord, but it's OK for the basics:http://www.timesheetsmts.com/adotutorial.htm

    This one updates, but you have to ensure your grid row &recordset row match when doing updates. This _might_ workwith your data-bound grid:http://www.officecomputertraining.co...ges/page37.asp

    Reply With Quote

    08-06-2005 10:58 PM

    Re: DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000Randy --

    Many thanks for the example code and the references.

    I will dig in to it.

    Larry

    "Randy Day" wrote in messagenews:[email protected]...> L Mehl wrote:> > Randy --> >> > Thanks for the suggestions.

    #5

    DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 2015/05/25

    http://objectmix.com/basic-visual/155832-datagrid-how-detect-change-any-field-1-row-then-update-table-vb6-sql-2000-a.html 4 / 6

  • VB programmer needed | Connection To SQL Database

    > >> > Can you tell me more about: 'UPDATE this row of the table> > Is the statement to use ... rsCaseSiteFetch.UpdateBatch adAffectAll ?>> I've never heard of 'updatebatch', so> I couldn't say.>> Please ignore any lousy indentation below;> I'm trying to avoid word wrap! >> '------------------------> dim Rst as ADODB.Recordset> Dim Cmd as ADODB.Command>> cmd.activeconnection = Rst> cmd.commandtype = adcmdtext>> with rst> .open "select * from table1">> if .recordcount = 0 then> 'no records returned> else> grid1.rows = .recordcount> .movefirst> n = 0> do while not .eof> 'put your data in the grid cell-by-> 'cell. This allows you to do things> '(set cell colors, etc) based on the> 'incoming field values>> grid1.textmatrix(n,0)= .fields.item(0)> grid1.textmatrix(n,1)= iif(.fields.item(1)=true,"Yes","No")> grid1.textmatrix(n,2)= .fields.item(2)>> n=n+1> .movenext> loop> end if> end with>> private sub air_code_update()> Dim strText as string>> 'create a SQL UPDATE string using the specific> 'data from your grid row. I prefer this method> 'over the Rst.update method because I control the> 'actual SQL command being sent to the DB engine>> strText = "Update table1 set field1=" + grid1> strtext = strText + " where ">> cmd.commandstring=strText> cmd.execute> end sub>> >> > I think I had better prepare for multiple-row updates.> >> > Where do I learn how to set up forms not using data-bound controls?> >>> This one doesn't give an example of updating an existing> record, but it's OK for the basics:> http://www.timesheetsmts.com/adotutorial.htm>> This one updates, but you have to ensure your grid row &> recordset row match when doing updates. This _might_ work> with your data-bound grid:> http://www.officecomputertraining.co...ges/page37.asp

    Reply With Quote

    + Reply to Thread

    Cannot update linked Paradox table field with DAO recordset?By Application Development in forum ADO DAO RDO RDS

    Replies: 4Last Post: 10-15-2007, 11:38 AM

    update table field from unbound form controlBy Application Development in forum ADO DAO RDO RDS

    Replies: 1Last Post: 08-17-2007, 12:54 AM

    Put aray values into a table to populate a DataGrid - VB6, SQL 2000By Application Development in forum ADO DAO RDO RDS

    Replies: 2Last Post: 07-14-2005, 11:34 AM

    DataGrid - can't update a cell - VB6, SQL 2000 Replies: 7

    Similar Threads

    DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 2015/05/25

    http://objectmix.com/basic-visual/155832-datagrid-how-detect-change-any-field-1-row-then-update-table-vb6-sql-2000-a.html 5 / 6

  • Contact Us ObjectMix Privacy Statement Top

    All times are GMT -5. The time now is 05:17 PM.

    Powered by vBulletin Version 4.1.3 Copyright 2015 vBulletin Solutions, Inc. All rights reserved.

    Content Relevant URLs by vBSEO 3.6.0 2011, Crawlability, Inc.

    By Application Development in forum ADO DAO RDO RDS Last Post: 07-14-2005, 01:22 AM

    Re: Change Table Links in MSAccess 2000 ART using VB6By Application Development in forum ADO DAO RDO RDS

    Replies: 0Last Post: 08-23-2003, 07:49 AM

    DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 2015/05/25

    http://objectmix.com/basic-visual/155832-datagrid-how-detect-change-any-field-1-row-then-update-table-vb6-sql-2000-a.html 6 / 6

    DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000 - basic.visualDataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000LinkBackThread Tools

    DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000Re: DataGrid - how detect a change in any field in 1 row, and thenupdate table? VB6, SQL 2000Re: DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000Re: DataGrid - how detect a change in any field in 1 row, and thenupdate table? VB6, SQL 2000Re: DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000Similar ThreadsCannot update linked Paradox table field with DAO recordset?update table field from unbound form controlPut aray values into a table to populate a DataGrid - VB6, SQL 2000DataGrid - can't update a cell - VB6, SQL 2000Re: Change Table Links in MSAccess 2000 ART using VB6