This topic is locked

Master/Detail Importing

12/23/2008 6:47:59 PM
ASPRunnerPro General questions
D
dlangham author

Hi,
I am using ASPRunner 6.0 and I have a Master/Detail page, I have the Import function enabled for the detail page and would like to use it to import data to the detail table so that the records will be assigned to the master table record, but currently this imports to the detail table but doesn't update the ID field to reflect this, I know I could just add a new record, but would like the option to import possibly hundreds of detail records.

Currently this all works as it should except for the import function.

I understand that this will require capturing the master key in some way to populate the detail key field when the import happens.

Has anyone done this, if so could you give me some sample code on how to do this please?
Merry Christmas

J
Jane 12/24/2008

answered in your personal email.

E
enfoque_traza 1/1/2009

Hi, I'm having the same problem. Could you please tell me also the solution? Thanks! The way I found is to import the same master key for all the records... but this is not the desirable solution, isn't i?

D
dlangham author 1/1/2009

Hi,
Below is the solution Jane worked out for me.
Please find the following code section in your xxx_import.asp file:

For i=0 to rs.Fields.Count-1

fields(i) = rs.Fields(i).Name

fields_list = fields_list & AddFieldWrappers(fields(i))

if i<>rs.Fields.Count-1 then fields_list = fields_list & ","

Next


Then add this code directly below it replacing the existing code:
if SESSION(strTableName & "_masterkey1")<>"" or SESSION(strTableName & "_masterkey1")<>0 or not isnull(Session("IMPORT_TEST_masterkey1")) then

fields_list = fields_list & ",[IMP_ID2]"

end if
Then find the following in the same page:

values_list = values_list & values(j)

if j<>rs.Fields.Count-1 then values_list = values_list & ","



next


Replace the existing code with the below code:
if SESSION(strTableName & "_masterkey1")<>"" or SESSION(strTableName & "_masterkey1")<>0 or not isnull(Session("IMPORT_TEST_masterkey1")) then

values_list = values_list & "," & SESSION("dbo.IMPORT_TEST_masterkey1")

end if
Please change the BOLD sections to match your app.

Where IMPORT_TEST is your app name, dbo.IMPORT_TEST is your table and [IMP_ID2] is your masterkey column in your detail table.

I hope this helps.

I have also asked for this option to be added to a future release.

D
Data_Frontiers 1/26/2009

Hi, Could you please be more specific on what code to "replace" directly below? Both instructions are a bit vaugue. I really appreciate your help!!!

Hi,

Below is the solution Jane worked out for me.
Please find the following code section in your xxx_import.asp file:

For i=0 to rs.Fields.Count-1

fields(i) = rs.Fields(i).Name

fields_list = fields_list & AddFieldWrappers(fields(i))

if i<>rs.Fields.Count-1 then fields_list = fields_list & ","

Next


Then add this code directly below it replacing the existing code:
if SESSION(strTableName & "_masterkey1")<>"" or SESSION(strTableName & "_masterkey1")<>0 or not isnull(Session("IMPORT_TEST_masterkey1")) then

fields_list = fields_list & ",[IMP_ID2]"

end if
Then find the following in the same page:

values_list = values_list & values(j)

if j<>rs.Fields.Count-1 then values_list = values_list & ","
next


Replace the existing code with the below code:
if SESSION(strTableName & "_masterkey1")<>"" or SESSION(strTableName & "_masterkey1")<>0 or not isnull(Session("IMPORT_TEST_masterkey1")) then

values_list = values_list & "," & SESSION("dbo.IMPORT_TEST_masterkey1")

end if
Please change the BOLD sections to match your app.

Where IMPORT_TEST is your app name, dbo.IMPORT_TEST is your table and [IMP_ID2] is your masterkey column in your detail table.

I hope this helps.

I have also asked for this option to be added to a future release.

D
dlangham author 1/26/2009

Hi,

Sorry if it was not too clear, I will try to explain a bit better.
Find the following script section in you xxx_import.asp file:

For i=0 to rs.Fields.Count-1

fields(i) = rs.Fields(i).Name

fields_list = fields_list & AddFieldWrappers(fields(i))

if i<>rs.Fields.Count-1 then fields_list = fields_list & ","

Next
----Add code here
for k=0 to UBound(keys)

if not InArray(fields, keys(k)) then

keys_present=0

Exit For

end if

Next


Add the following code into the above where I have inserted ----Add code here

if SESSION(strTableName & "_masterkey1")<>"" or SESSION(strTableName & "_masterkey1")<>0 or not isnull(Session("IMPORT_TEST_masterkey1")) then

fields_list = fields_list & ",[IMP_ID2]"

end if


Your end result should look like the below:

For i=0 to rs.Fields.Count-1

fields(i) = rs.Fields(i).Name

fields_list = fields_list & AddFieldWrappers(fields(i))

if i<>rs.Fields.Count-1 then fields_list = fields_list & ","

Next
if SESSION(strTableName & "_masterkey1")<>"" or SESSION(strTableName & "_masterkey1")<>0 or not isnull(Session("IMPORT_TEST_masterkey1")) then

fields_list = fields_list & ",[IMP_ID2]"

end if


for k=0 to UBound(keys)

if not InArray(fields, keys(k)) then

keys_present=0

Exit For

end if

Next


Then find the following code section:

values_list = values_list & values(j)

if j<>rs.Fields.Count-1 then values_list = values_list & ","



next
----Add code here
sql = "insert into [dbo].[IMPORT_TEST] (" & fields_list & ") values (" & values_list & ")"
On Error Resume Next
dbConnection.Execute sql
if Err.Number=0 then



goodlines = goodlines+1


Then add the following code into the above where I have inserted ----Add code here

if SESSION(strTableName & "_masterkey1")<>"" or SESSION(strTableName & "_masterkey1")<>0 or not isnull(Session("IMPORT_TEST_masterkey1")) then

values_list = values_list & "," & SESSION("dbo.IMPORT_TEST_masterkey1")

end if


You should end up with something like the below code:

values_list = values_list & values(j)

if j<>rs.Fields.Count-1 then values_list = values_list & ","



next
if SESSION(strTableName & "_masterkey1")<>"" or SESSION(strTableName & "_masterkey1")<>0 or not isnull(Session("IMPORT_TEST_masterkey1")) then

values_list = values_list & "," & SESSION("dbo.IMPORT_TEST_masterkey1")

end if


sql = "insert into [dbo].[IMPORT_TEST] (" & fields_list & ") values (" & values_list & ")"
On Error Resume Next
dbConnection.Execute sql
if Err.Number=0 then



goodlines = goodlines+1


Where IMPORT_TEST is your app name, dbo.IMPORT_TEST is your table and [IMP_ID2] is your masterkey column in your detail table.

I hope this helps.