Saturday, December 26, 2020

T-SQL Transaction Most Basic Example


                BEGIN TRANSACTION

                                DECLARE @newID INT;


                                --For testing, bad SQL goes here:

                                --INSERT INTO Intake(intake_id, name, pet) VALUES (39,'Ape', 'Dog')


                                --Good SQL goes here:



                                    INSERT INTO Intake(res_name) VALUE("joe");



                                SET @newID =scope_identity();


                                INSERT INTO Intake_ISC_lutb(Intake_ID, ISC_Guid)VALUES(@newID, 'Smedly')


                COMMIT TRAN



                IF @@TRANCOUNT > 0

                                ROLLBACK TRAN

                                --RAISERROR('Error raised in Intake', 16,1)


GridView buttons and commands Delete

 You have a GridView and you want a simple Delete button. What are your options?

Most basic would be to use the CommandField (the Wizard will take you here, too).

Main points are:

In the <asp:Gridview> , after the <columns>, before the <asp:BoundField> items, you would see:

<asp:CommandField ..... (tbd???)

and it is incumbant upon the asp:SqlDataSource to have a section called:

DeleteCommand="" with the actual SQL to be used.

The only other power you have is to include a OnRowDeleted="{create event}" in the <asp:GridView> block, to do something like handle EXCEPTIONS (example: gvResources_RowDeleted).

You can customize how the "Delete" button looks like (Wizard will default to a link that says "Delete" in the same column as Add and Edit, generally in first column) by a bunch of optional properties in the <asp:CommandField> tag:



DeleteText="Delete" (default from Wizard)

??? ShowDeleteButton="True" ????

For example, see my Forecast Resources Index page gridview.

The next way to create a "delete button" would be with a ButtonField (or a TemplateField???) but that would be overkill so long as any delete operation can be accomplished with either a SQL statement or even Stored Proc (since the CommandField can also call a stored proc).

However, let's say you prefer to, instead of calling a SQL statement stored in either the ASPX file or SQL Server (for sprocs), but in a data persistence class, maybe a ButtonField is for you.

Seemingly confusingly, to use a ButtonField, you have to specify a handler in the <asp:Gridview block named OnRowCommand="", which sounds like you are using the CommandField!!! 


<asp:buttonfield buttontype="Button" commandname="DeleteThis" text="Del"/>

.void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e)

if(e.CommandName=="DeleteThis") { // Convert the row index stored in the CommandArgument // property to an Integer. int index = Convert.ToInt32(e.CommandArgument); // Get the last name of the selected author from the appropriate // cell in the GridView control. GridViewRow selectedRow = GridView1.Rows[index]; TableCell contactName = selectedRow.Cells[1]; ...

    //do delete


I learned that if you use the CommandName="Delete" you will get an error b/c of clash with other functionality.....Also remember to rebind the grid.

Tuesday, December 22, 2020

NuGet Hack

It is possible to also reference DLLs instead of NuGet packages. Change the .nupkg extension of the packages to .zip, unzip them, and extract the DLL files. Then uninstall the NuGet packages from each project and replace them with DLL references.

Tuesday, December 15, 2020

Group Policy: So You Want To Know What the Sys Admins Did To You

 How to See Which Group Policies Are Applied to Your PC and User Account


(Resultant Set of Policy)

Takes a while to render when you try to expand.

For more:

For Remote Desktop timeout info:

Computer Configuration → Administrative Templates → Windows Components → Remote Desktop Services → Remote Desktop Session Host → Session Time Limit.

To Edit Group Policy:


Create Database Project in Visual Studio 2017


Here's where you can get a Connection String if you want for later:

It is selectable!

Some options:

Click START.... and....

Click Finish