This topic is locked
[SOLVED]

 Before Record Added

7/5/2016 12:21:38 PM
ASPRunner.NET General questions
M
markynewport author

Hi there,
I am trying to add data to another table in asp.net in ther before record updated on the edit page, I used to do this in asprunner pro with the following code.
'** Insert a record into another table ****

if values("field1")<> "field1value" then

Response.Write "No visit entered"

else

set dal_table=dal.Table("table2")

dal_table.visitID=values("ID")

dal_table.updatedvalue=values("updatedby")

dal_table.dateupdated=values("dateupdated")

dal_table.Add()
end if

I have tried the below code but no joy.
dynamic tbltable1 = GlobalVars.dal.Table("table1");

tbltable1_history.Value["VisitID"] = values("ID");

tbltable1_history.Value["visited_by"] = values("updatedby");

tbltable1_history.Value["visitdate"] = values("dateupdated");

tbltable1_history.Add();
Any help greatly appreciated.
Regards,

Mark.

M
markynewport author 7/6/2016



Hi there,
I am trying to add data to another table in asp.net in ther before record updated on the edit page, I used to do this in asprunner pro with the following code.
'** Insert a record into another table ****

if values("field1")<> "field1value" then

Response.Write "No visit entered"

else

set dal_table=dal.Table("table2")

dal_table.visitID=values("ID")

dal_table.updatedvalue=values("updatedby")

dal_table.dateupdated=values("dateupdated")

dal_table.Add()
end if

I have tried the below code but no joy.
dynamic tbltable1 = GlobalVars.dal.Table("table1");

tbltable1_history.Value["VisitID"] = values("ID");

tbltable1_history.Value["visited_by"] = values("updatedby");

tbltable1_history.Value["visitdate"] = values("dateupdated");

tbltable1_history.Add();
Any help greatly appreciated.
Regards,

Mark.


I have modified the above to
dynamic tbltable1 = GlobalVars.dal.Table("table1");

tbltable1.Value["status"] = values["name"];

tbltable1.Value["visitID"] = values["ID"];

tbltable1.Value["updatedate"] = values["dateupdated"];

tbltable1.Add();
The name to status and the dateupdated to updatedate work fine,

its the ID to visitID I am getting a VisitID of zero all the time.

I have the two tables linked, ID to visitID

jadachDevClub member 7/6/2016

How about this - after record updated?
dynamic tbltable1 = GlobalVars.dal.Table("table1");

tbltable1.Value["VisitID"] = values["ID"];

tbltable1.Value["visited_by"] = values["updatedby"];

tbltable1.Value["visitdate"] = values["dateupdated"];

tbltable1.Add();

M
markynewport author 7/8/2016



How about this - after record updated?
dynamic tbltable1 = GlobalVars.dal.Table("table1");

tbltable1.Value["VisitID"] = values["ID"];

tbltable1.Value["visited_by"] = values["updatedby"];

tbltable1.Value["visitdate"] = values["dateupdated"];

tbltable1.Add();


Thanks Jerry,
Worked Perfect,
Just thought the "before record added" the ID was not created, Thanks for your help I really appreciate it.
Regards,

Mark.

Sergey Kornilov admin 7/8/2016

This is correct, if you use an autonumber/autoincrement column its value doesn't yet exist in BeforeAdd event. In this case you need to use AfterAdd event and keys["KeyColumnName"] instead of values["KeyColumnName"]

M
markynewport author 7/13/2016

Hi Jerry,

Can i pick your brain again,
I was hoping to insert a value into a field ("record reviewed") when the user clicks on the view icon for that record.
I have tried inserting in the "JavaScript Onload" event for the view page.
values["referral_reviewed"] = ("Yes");
This does not work.
Thanks,

Mark.

jadachDevClub member 7/13/2016

You can do it on the edit page. Make your fields read only if you don't want the users making changes. Then in Before record updated, use values["referral_reviewed"] = "Yes";

M
markynewport author 8/5/2016

I forgot to add back in the conditional statement at the start of
dynamic tbltable1 = GlobalVars.dal.Table("table1");

tbltable1.Value["VisitID"] = values["ID"];

tbltable1.Value["visited_by"] = values["updatedby"];

tbltable1.Value["visitdate"] = values["dateupdated"];

tbltable1.Add();

tbltable1.Add();
I was trying
if ((values["visit_history"])== "Yes") but getting a compile error.
Thanks,

Mark.

M
markynewport author 8/5/2016

I forgot to add back in the conditional statement at the start of
dynamic tbltable1 = GlobalVars.dal.Table("table1");

tbltable1.Value["VisitID"] = values["ID"];

tbltable1.Value["visited_by"] = values["updatedby"];

tbltable1.Value["visitdate"] = values["dateupdated"];

tbltable1.Add();

tbltable1.Add();
I was trying
if ((values["visit_history"])== "Yes") but getting a compile error.
Thanks,

Mark.

jadachDevClub member 8/5/2016

Try something like this:
if (values["visit_history"] == "Yes")

{

dynamic tbltable1 = GlobalVars.dal.Table("table1");

tbltable1.Value["VisitID"] = values["ID"];

tbltable1.Value["visited_by"] = values["updatedby"];

tbltable1.Value["visitdate"] = values["dateupdated"];

tbltable1.Add();

}

else

{

// do nothing

}