Using DataGrid VB6
Using DataGrid VB6
2015/05/25
User Name
Password
Log in
Help
Remember Me?
Forum
What's New?
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 ...
+ 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
#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
#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
#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" <[email protected]> wrote in message
news:[email protected]...
> 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 to Thread
VB programmer needed | Connection To SQL Database
Similar Threads
Put aray values into a table to populate a DataGrid - VB6, SQL 2000
By Application Development in forum ADO DAO RDO RDS
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
Replies: 0
Last Post: 08-23-2003, 07:49 AM
http://objectmix.com/basic-visual/155832-datagrid-how-detect-change-any-field-1-row-then-update-table-vb6-sql-2000-a.html
6/6