CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 INSERT MULTIPLE ROWS FROM AN EDITABLE GRID TO A TABLE

Print topic Send  topic

Author Message
sjgrodriguez

Posts: 26
Posted: 03/28/2011, 2:05 AM

Hi there. This is probably simple, but im having headaches trying to find the solution for this.

I have an editable grid called GRID_EDAR from a table called EDAR with 2 fields named NAME (Text) and AGE (integer). It has 23 rows (so the grid has 2 columns and 23 rows).

What i want is with an event, to insert all the rows showed from the grid at a time(which can be all the rows of the table or only some of them, depending on the parameters) to a different table called EDAR_COPY, which has the same two fields: NAME and AGE.

Im trying with this code, but it doesnŽt work:

Function GRID_EDAR_DataSource_AfterExecuteUpdate(Sender)

'Custom Code @14-73254650
' -------------------------
GRID_EDAR.DataSource.CmdExecution = False
Dim SQL
Dim Connection
Dim ErrorMessage
Set Connection = New clsDBDEPURADORAS_ACUM11
Connection.Open
SQL = "INSERT INTO EDAR_COPY (NAME,AGE) SELECT NAME,AGE FROM EDAR
Connection.Execute(SQL)
ErrorMessage = CCProcessError(Connection)
Connection.Close
Set Connection = Nothing
On Error Goto 0
' Write your own code here.
' -------------------------
'End Custom Code

End Function 'Close GRID_EDAR_DataSource_AfterExecuteUpdate @2-54C34B28


Could you please help me??

Thanks a lot !!

Sergio
View profile  Send private message
TheunisP

Posts: 342
Posted: 03/28/2011, 2:10 AM

have you tried using the custom insert option?
View profile  Send private message
sjgrodriguez

Posts: 26
Posted: 03/28/2011, 4:21 AM

Hi. Thanks very much for the quick answer.

No, i have never tried it. Im going to check if this fit my needs. I will tell you.

Regards,

Sergio
View profile  Send private message
TheunisP

Posts: 342
Posted: 03/28/2011, 4:43 AM

a quick primer from custom insert - pick method table
in the custom insert dialog pick your table
match up the fields with your fields

a non standard use would also be to use the standard update and custom update on the same record/editable grid

e.g. you setup the standard stuff, do the custom section - and this moment CCS will only do you custom, you then invoke the standard update or insert as custom code eg. yourrecordname.update which will force CCS to to the standard one as well - voila you update 2 tables with 1 line of code ;-)
View profile  Send private message
sjgrodriguez

Posts: 26
Posted: 03/28/2011, 5:13 AM

Great, thank you for the tip !!

One question. Does the custom insert method work only with new rows added at the time? I mean. What i want is to insert all the existing rows from the main table (the one of the editable grid), that already exist in the table, to the secondary table and not the new rows added with the editing grid.

If i use the custom update method, i need in the secondary table the rows previously to be created with the ID matching the main table...

So the cool thing would be that the secondary table, being empty of rows, will add new rows after using the update of insert method.

Is this possible with the custom methods?

I hope im explaining.

Thanks in advance !!

Sergio
View profile  Send private message
TheunisP

Posts: 342
Posted: 03/28/2011, 5:52 AM

mmm that is a good question - when you use the custom just exactly gets inserted - I havent got a db/project that I can test it on now - would you check and reply - would love to know
View profile  Send private message
sjgrodriguez

Posts: 26
Posted: 03/28/2011, 5:59 AM

Nice, thanks. IŽll be waiting for your answer..

Sergio
View profile  Send private message
TheunisP

Posts: 342
Posted: 03/28/2011, 6:05 AM

ok this is how I see it - each row in the editable grid has a unique key or not if it is new - when CCS cycles through it it will try and match the key if not there an insert otherwise if it finds a match it update the table - that is why we can do both updates & insert from the editable grid at the same time

so if you clean out the seond grid it should always insert - but that is my theory and I havent checked it against the code yet
View profile  Send private message
Waspman

Posts: 948
Posted: 03/28/2011, 11:57 AM

I've done this many times. You can hijack the custom update (and delete actually)

One thing, I always work with custom created unique id's never auto id's, makes things a lot easier:)

Build the master table and and copy table with the same fields.

Create your editable grid as you normally would. Then go to custom insert and go through the screens as if you were going to append the copy table. Then switch the custom insert type to sql and copy the script from the window.

Now go to custom update and and go through it as if it were going to update the master table. Then switch to sql and paste the code you copied from the custom insert into the custom update. Now when the form tries to update it will insert the data into your copy table.

You can also hijack the the custom delete. Which means you can use the delete checkbox to allow the user to select which fields to insert/update. Nice for quizzes etc.

Next stage is to log that the user has updated the copy table so when they return the source of the data is the copy table not the master tabel and they can now continue to update their version of the original data.

I used this for a student questionnaire. The client set and changed the questions. The first time round the student completed the questions and their answers were transferred the the replica table along with the student id. When the student returned they could keep updating their answers whenever they wanted in the copy table. (It makes sense to me hahaha)


HTH

;-)
_________________
http://www.waspmedia.co.uk
View profile  Send private message
sjgrodriguez

Posts: 26
Posted: 03/28/2011, 12:41 PM

Hey thanks Waspman and TheunisP. I really appreciate your comnents and suggestions.

So Waspman, im gonna try your idea and i will tell you.

Regarding the checkbox, is there a way to setup the checkbox so that all the rows are checked/unchecked at the same time (similar that gmail does with emails)?

Thanks in advance.

Sergio
View profile  Send private message
TheunisP

Posts: 342
Posted: 03/28/2011, 12:54 PM

@waspman - brilliant - that is a nice to remember, never even thought of hijacking it in that way
View profile  Send private message
Waspman

Posts: 948
Posted: 03/28/2011, 1:15 PM

Quote sjgrodriguez:
Hey thanks Waspman and TheunisP. I really appreciate your comnents and suggestions.

So Waspman, im gonna try your idea and i will tell you.

Regarding the checkbox, is there a way to setup the checkbox so that all the rows are checked/unchecked at the same time (similar that gmail does with emails)?

Thanks in advance.

Sergio

Yep, simple bit of javascript on the column header. I'll dig it out and post it....
_________________
http://www.waspmedia.co.uk
View profile  Send private message
Waspman

Posts: 948
Posted: 03/28/2011, 1:27 PM

Found it!

PM me your email and I'll send the js file over. T
_________________
http://www.waspmedia.co.uk
View profile  Send private message
sjgrodriguez

Posts: 26
Posted: 03/29/2011, 12:25 AM

@waspman Excellent. The code works perfectly ! Thank you.

@TheunisP thanks for your support !

Now i have a cool tool for my applications hehe

See you soon !

Sergio
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.