Sie sind auf Seite 1von 6

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

VB6, SQL 2000

2015/05/25
User Name

Password

Log in

Help

Remember Me?

Forum

What's New?

FAQ Calendar Forum Actions

Advanced Search

Quick Links

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 row s 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 ...

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
Results 1 to 5 of 5

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

Thread Tools

#1

08-05-2005 07:53 PM

Application Development
Junior Member
Join Date:
Nov 2009
Posts:
0

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

Reply With Quote

#2

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:

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

1/6

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

2015/05/25

> 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!
<holds up fingers in a cross to ward off the evil>

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

#3

08-06-2005 12:18 AM

Re: DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000
Randy -Thanks for the suggestions.
Can you tell me more about: 'UPDATE this row of the table
Is 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
http://objectmix.com/basic-visual/155832-datagrid-how-detect-change-any-field-1-row-then-update-table-vb6-sql-2000-a.html

2/6

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

2015/05/25

"Randy Day" <ruthal@sasktel.nex> wrote in message


news:11f8b1te3pcnmc4@corp.supernews.com...
> L Mehl wrote:
>
> > 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!
> <holds up fingers in a cross to ward off the evil>
>
>
>
> 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

#4

08-06-2005 12:24 PM

Re: DataGrid - how detect a change in any field in 1 row, and thenupdate table? VB6, SQL 2000
L Mehl wrote:
> Randy ->
> Thanks for the suggestions.
http://objectmix.com/basic-visual/155832-datagrid-how-detect-change-any-field-1-row-then-update-table-vb6-sql-2000-a.html

3/6

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

2015/05/25

>
> 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 <condition>"
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

#5

08-06-2005 10:58 PM

Re: DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000
Randy -Many thanks for the example code and the references.
I will dig in to it.
Larry
"Randy Day" <ruthal@sasktel.nex> wrote in message
news:11f9skn72c59s1c@corp.supernews.com...
> L Mehl wrote:
> > Randy ->>
> > Thanks for the suggestions.
http://objectmix.com/basic-visual/155832-datagrid-how-detect-change-any-field-1-row-then-update-table-vb6-sql-2000-a.html

4/6

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

2015/05/25

>>
> > 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 <condition>"
>
> 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
VB programmer needed | Connection To SQL Database
Similar Threads

Cannot update linked Paradox table field with DAO recordset?


By Application Development in forum ADO DAO RDO RDS

update table field from unbound form control


By Application Development in forum ADO DAO RDO RDS

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

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


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

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

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

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

Replies: 7
5/6

DataGrid - how detect a change in any field in 1 row, and then update table? VB6, SQL 2000
By Application Development in forum ADO DAO RDO RDS

2015/05/25
Last Post: 07-14-2005, 01:22 AM

Re: Change Table Links in MSAccess 2000 ART using VB6


By Application Development in forum ADO DAO RDO RDS

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

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.

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

6/6

Das könnte Ihnen auch gefallen