hansel
February 20th, 2000, 09:30 PM
I have witnessed the slow-down in performance,
particularly when one has a form with many Adodc controls (say, for example,
when one needs to make selections from DataCombos). In my case, the form has
many textboxes and about seven Datacombo controls. I am led to believe the
approach I used by binding the controls to related Adodc controls on the
form has a performance penalty. So, I am trying to re-write most of what I
have in code (i.e. without using the ado controls supplied in vb6).
I progressed fine, but ran into trouble when
trying to bind the datacombo in code. I insert below my code:
' Code in MainForm
' This is just a demo test-drive program.
private cbo as DataCombo
private depRS as ADODB.recordset 'I created this recordset for the
datacombo, which contains all the department names (about 90) from
' a table
in the database called Dept. There are two tables in the database- Dept and
Employees.
' The database fields are as follows:
' for table named Dept-> ID, DeptName
' for table named Employees-> ID, DeptName, FirstName, LastName
private recordset as ADODB.recordset ' for main employees table
private connection as ADODB.connection
private Sub cmdConnect_Click()
set recordset = new ADODB.recordset
set depRS = new ADODB.recordset
set connection = new ADODB.connection
connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
"Data
Source=c:\windows\desktop\dbtest.mdb"
connection.Open
recordset.Open "Employees", connection, adOpenKeyset
depRS.Open "Dept", connection, adOpenKeyset
' I have attempted to initialise the datacombo with the data from the
database table
for Each cbo In me.dcboDeptName
set cbo.DataSource = recordset
set cbo.RowSource = depRS
cbo.DataField = "DeptName"
cbo.ListField = "DeptName"
cbo.BoundColumn = "DeptName"
next
'Bind the text boxes to the data provider
populateFields
End Sub
private Sub populateFields()
txtFirstName.Text = recordset.Fields("FirstName")
txtLastName.Text = recordset.Fields("LastName")
dcboDeptName(0).Text = recordset.Fields("DeptName") ' I am not sure
about this one
End Sub
private Sub cmdNext_Click()
on error GoTo GoNextError
recordset.MoveNext
If recordset.EOF then recordset.MoveLast
populateFields
Exit Sub
GoNextError:
MsgBox Err.Description
End Sub
private Sub cmdPrev_Click()
on error GoTo GoPrevError
recordset.MovePrevious
If recordset.BOF then recordset.MoveFirst
populateFields
Exit Sub
GoPrevError:
MsgBox Err.Description
End Sub
private Sub Form_Unload(cancel as Integer)
If Not (recordset is nothing) then
recordset.Close
depRS.Close
connection.Close
set recordset = nothing
set connection = nothing
End If
End Sub
Well, my problem is that when I make a department selection from the
datacombo, It is not updating the "DeptName" field in the Employees table.
Also, when I fire the next or previous button the fields on the forms are
displayed accordingly. However, I try to make a department selection and
then press Prev or Next buttons I get the following error: "The change was
canceled during notification; no columns are changed"
Well, that's it. I'd appreciate any suggestions or examples or corrections
regarding the use of DataCombo with code.
Sincerely,
Hansel
hansel@solutions2000.net
particularly when one has a form with many Adodc controls (say, for example,
when one needs to make selections from DataCombos). In my case, the form has
many textboxes and about seven Datacombo controls. I am led to believe the
approach I used by binding the controls to related Adodc controls on the
form has a performance penalty. So, I am trying to re-write most of what I
have in code (i.e. without using the ado controls supplied in vb6).
I progressed fine, but ran into trouble when
trying to bind the datacombo in code. I insert below my code:
' Code in MainForm
' This is just a demo test-drive program.
private cbo as DataCombo
private depRS as ADODB.recordset 'I created this recordset for the
datacombo, which contains all the department names (about 90) from
' a table
in the database called Dept. There are two tables in the database- Dept and
Employees.
' The database fields are as follows:
' for table named Dept-> ID, DeptName
' for table named Employees-> ID, DeptName, FirstName, LastName
private recordset as ADODB.recordset ' for main employees table
private connection as ADODB.connection
private Sub cmdConnect_Click()
set recordset = new ADODB.recordset
set depRS = new ADODB.recordset
set connection = new ADODB.connection
connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
"Data
Source=c:\windows\desktop\dbtest.mdb"
connection.Open
recordset.Open "Employees", connection, adOpenKeyset
depRS.Open "Dept", connection, adOpenKeyset
' I have attempted to initialise the datacombo with the data from the
database table
for Each cbo In me.dcboDeptName
set cbo.DataSource = recordset
set cbo.RowSource = depRS
cbo.DataField = "DeptName"
cbo.ListField = "DeptName"
cbo.BoundColumn = "DeptName"
next
'Bind the text boxes to the data provider
populateFields
End Sub
private Sub populateFields()
txtFirstName.Text = recordset.Fields("FirstName")
txtLastName.Text = recordset.Fields("LastName")
dcboDeptName(0).Text = recordset.Fields("DeptName") ' I am not sure
about this one
End Sub
private Sub cmdNext_Click()
on error GoTo GoNextError
recordset.MoveNext
If recordset.EOF then recordset.MoveLast
populateFields
Exit Sub
GoNextError:
MsgBox Err.Description
End Sub
private Sub cmdPrev_Click()
on error GoTo GoPrevError
recordset.MovePrevious
If recordset.BOF then recordset.MoveFirst
populateFields
Exit Sub
GoPrevError:
MsgBox Err.Description
End Sub
private Sub Form_Unload(cancel as Integer)
If Not (recordset is nothing) then
recordset.Close
depRS.Close
connection.Close
set recordset = nothing
set connection = nothing
End If
End Sub
Well, my problem is that when I make a department selection from the
datacombo, It is not updating the "DeptName" field in the Employees table.
Also, when I fire the next or previous button the fields on the forms are
displayed accordingly. However, I try to make a department selection and
then press Prev or Next buttons I get the following error: "The change was
canceled during notification; no columns are changed"
Well, that's it. I'd appreciate any suggestions or examples or corrections
regarding the use of DataCombo with code.
Sincerely,
Hansel
hansel@solutions2000.net