|
-
Jan 17th, 2003, 09:40 AM
#1
Thread Starter
New Member
using arrays as a datasource for datagrid
this is a complicated question and if i dont explain properly, or you need more info, please let me know..any help would be greatly appreciated!
at present, i have bound my datagrid to a "temporary" table (OrderDetails2) in the database, which is only being used for the purposes of the datagrid. instead i wish to bind the datagrid to an array and save the contents of the datagrid later, based on this array. the way the form is working right now is that Textboxes for ProductCode, ProductDesc,txtQuantity and txtFullPrice and when a command button is hit, the OrderDetails2 table is updated and the datagrid is populated correspondingly. Similarly, this happens when the command button is pressed for a second, third time etc. What i wish to happen to store the values in an array, and populate the datagrid this way, and when the command button is hit again , the (dynamic) array is redimmed and the datagrid updates corresponding. how could i go about this or is it even possible?! i have very little experience with arrays ( and indeed datagrids!)
Thanks in advance!
-
Jan 17th, 2003, 02:55 PM
#2
Fanatic Member
Arrays can't be bound to a datagrid.
Array (static or dynamic) can be looped manually into a msflexgrid.
Anyway, an array isn't necessary if a disconnected recordset is used with a datagrid.
To do this, the connection must be client side, and the recordset locktype must be adLockBatchOptimistic:
set Cn.CursorLocation = adUseClient
set rsOrderDetails2.LockType = adLockBatchOptimistic
set datagrid1.Datasource = rsOrderDetails2 'binds the datagrid
'disconnect the recordset so it doesn't update the database:
set rsOrderDetails2.ActiveConnection = nothing
'do whatever with the rs:
rsOrderdetails2.Addnew
etc, .Update
'To view the new set in the grid, reset the datasource:
set datagrid1.Datasource = rsOrderDetails2
When it's time to update the DB, reset the connection and update the whole batch:
set rsOrderDetails2.ActiveConnection = Cn
rsOrderDetails2.UpdateBatch
VB 6.0, Access, Sql server, Asp
-
Jan 17th, 2003, 03:52 PM
#3
Thread Starter
New Member
Thank you so much for your time and effort at supplying such code, i have some questions though ( i am sorry to be so awkward!)....a bug is thrown saying that " operation not allowed when object is closed", how do i open the recordset ( the conn is already opened on loading of project). also, when the datagrid is sourced to the RS the second time, does is overwrite whats already in the grid or append whats already there? Thank so much again!
-
Jan 17th, 2003, 04:39 PM
#4
Fanatic Member
btw-I suppose also the temp table OrderDetails2 can be done away with and replaced with rsOrderDetails.
Do you mean closed here?
then:
sql = "select * from OrderDetails"
rsOrderDetails.Open sql, cn
set datagrid1.Datasource = rsOrderDetails
etc
or if it's closed here then:
set rsOrderDetails.ActiveConnection = nothing
if rsOrderDetails.State = adStateClosed then rsOrderDetails.Open
rsOrderDetails.Addnew
etc
when the datagrid is sourced to the RS the second time, it "overwrites" as an entire display set in the grid (though the new info is actually appended in the rs itself). Does it make a difference?
When it updates the db, only new info is updated.
Last edited by ralph; Jan 17th, 2003 at 05:38 PM.
VB 6.0, Access, Sql server, Asp
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|