This topic is locked

Using SQL Views

4/3/2017 10:21:27 PM
ASPRunner.NET General questions
R
raymueller authorDevClub member

What is the best practice for using database generated views for adding and editing content?
I want to use a view that can be used to generate the list/view however if the user wants to add a new record or edit an existing record. How best can this be accomplished?
Thank you

Ray

T
Tim 4/4/2017

Hi Ray,
I'm not sure if it's "best practice" but there are 2 methods I use for this. One is to use the "Custom add"/"Custom record update" events and create my own insert/update statement(s) into the table(s) that need to be altered. Like this:
string sql = "UPDATE [dbo].[MyTable] SET [MyField] = '" + values["FormField"].ToString() + "' WHERE ID='" + oldvalues["ID"].ToString() + "';

CommonFunctions.db_exec(sql, null);
return false;
The second method works if you only need to add/update one underlying table but are showing fields (via the view) on the add/edit page from another table. In this case, in the "Before record added"/"Before record updated" event I add "values.Remove("NameOfField");" for all of the fields that aren't in the underlying table I want to affect. As long as all the fields that are getting added/updated are from one underlying table, this seems to work.
Hope this helps.

Good luck.

Tim

R
raymueller authorDevClub member 4/5/2017

Tim,
This is a slick method, simple and effective. I will try this implement this weekend.
Many thanks

Ray



Hi Ray,
I'm not sure if it's "best practice" but there are 2 methods I use for this. One is to use the "Custom add"/"Custom record update" events and create my own insert/update statement(s) into the table(s) that need to be altered. Like this:
string sql = "UPDATE [dbo].[MyTable] SET [MyField] = '" + values["FormField"].ToString() + "' WHERE ID='" + oldvalues["ID"].ToString() + "';

CommonFunctions.db_exec(sql, null);
return false;
The second method works if you only need to add/update one underlying table but are showing fields (via the view) on the add/edit page from another table. In this case, in the "Before record added"/"Before record updated" event I add "values.Remove("NameOfField");" for all of the fields that aren't in the underlying table I want to affect. As long as all the fields that are getting added/updated are from one underlying table, this seems to work.
Hope this helps.

Good luck.

Tim