SanjivaniPant.com

App_Data 04/10/2009
 

Hello Friends,
One of dotnetspider member raised a question on app_data in the forum, and that inspired me to write about this folder. I will explain why this folder resides in the web application. Its use and advantages.
Why App_Data folder:
App_Data folder reside in web application’s root folder. It is a reserved folder and it is there so that we can save our web site specific data related files such as database files (e.g. MS SQL Server, MS Access). You can have nested folders inside App_Data to organize your database files. One web site project can have only one App_Data folder.

To add database to App_Data, right click on the folder and select required data file. It provides you list of all possible data files.

To add existing database files, simply copy paste the files in App_Data and refresh the folder or go through Add existing files after right clicking the folder. Be aware of adding MS SQL server database files. You need to detach the database files first and then copy to the folder and reattach them.
Advantage of having App_Data folder:
1. It can be used for maintaining Membership(http://msdn.microsoft.com/en-us/library/yh26yfzy.aspx) and Roles managements(http://msdn.microsoft.com/en-us/library/5k850zwb.aspx)
2. If your web project is complicated enough like having *.cs and *.vb files, this folder will not get affected by that since it just saves your database files and to access database in all code behind files you can just use connection string of web.config file.
3. You can manage your database easily using server explorer

[The same article you can find
here]

Cheers!
Sanjivani

 
 

After Triggers

“After triggers” are triggers which get fired after executing SQL statement. After triggers are also knows as “For triggers” or simple triggers. In the old version of SQL server (prior to version 2000), these are the only triggers available. After trigger fires after Insert, Update and Delete actions.

To understand After trigger in the real world, lets create a dummy table first on which a After trigger will be created.

To create a table, open Microsoft SQL Server Management Studio and click on the menu File->New->Query

Note: You will have to select a database in which you want table created.

Copy paste or type below SQL statement in query window and run the SQL.


Create table Mytable ( col1 int )

Above Statement will create Mytable named table in the selected database.

Now let’s create After update trigger:

Create TRIGGER Mytable_triggeron Mytable
After Update

AS

Begin
Select
* from Mytable;
Select
* from inserted;
 Select * from deleted;
Select '------------------------';
End


Above trigger is using “inserted” and” deleted” logical tables. This is the advantage we got in trigger. We can see new value updated or inserted in “inserted” logical table and old values which got replaced by new values in “deleted” logical table.

Now insert few rows into Mytable so that we can modify them and see how trigger react to them.

insert into Mytable values(1);
insert
into Mytable values(2);
insert
into Mytable values(3);
insert into Mytable values(4);
insert into Mytable values(5);


Now fire the following update statement in query window

Update Mytable set col1=col1 * 2

After firing the above SQL statement you will see following result in the result panel

Observe that Mytable values got updated already when trigger got fired.

As there can be multiple after trigger on a table, to set order of triggers, there is sp_settriggerorder standard stored procedure available.


Conclusion:

From above steps it is proved that After triggers are fired after Insert /Update/ Delete actions.


Instead Of Triggers

After triggers fire after update/insert/delete action whereas Instead Of triggers fire in place of insert/update/delete action.

There can be only one Instead of trigger of a type on a table.

To see how Instead If triggers works,

Change above created table using following SQL statements:


ALTER TRIGGER [dbo].[Mytable_trigger]on [dbo].[Mytable]
Instead Of Update

AS

Begin

Select * from Mytable;

print 'Not allowing to update values'

Rollback;
End

Now reset Mytable values by firing following statements:

delete from Mytable;

insert into Mytable values(1);
insert
into Mytable values(2);
insert into Mytable values(3);
insert
into Mytable values(4);
insert into Mytable values(5);


Now ready to see what happens if we update the values of Mytable. Fire following update statement and notice the result
Update Mytable set col1=col1 * 2


Conclusion:

Result shows value of Mytable which did not update . So instead of trigger give us option to implement other logic instead of actual action. We can still get updated values in inserted table in, in case we have to validate updated values and then commit those.

[The same article you can find here]

Happy Triggering!
Sanjivani Kumar

 
 

Hello Friends,
As we all know we can not use checkboxlist control with required field validator control, we need to have a solution for that. I created a javascript function which will do the job of required field validator control. The JS function returns true or false. If checkboxlist control has got atleast one checkbox selected, the function will return true else it will return false.

I have CheckBoxList1 control on my web page. To validate that control here is the script. You will have to change control name in the script while implementing this script.



 function ValidateCheckboxList()
{
           
       var chkitems = document.getElementById('<%= CheckBoxList1.ClientID %>');
      
      var chkitm = chkitems.getElementsByTagName("input");
      
     for (var i = 0; i < chkitm.length; i++)
    {
           
          if (chkitm[i].checked)
           
          {                    
                   
             return true;
           
          }
      
   }
      
    return false;

}



To Implement, simply call this function wherever you need. I called this function on a button click event.


 <asp:CheckBoxList ID="CheckBoxList1" runat="server">           
       <asp:ListItem>a</asp:ListItem>
                 
       <asp:ListItem>b</asp:ListItem>
           
       <asp:ListItem>c</asp:ListItem>

</asp:CheckBoxList>


<input id="Button1" type="button" value="Validate checklist"
            onclick="return ValidateCheckboxList();" />



[The same article you can find here]

~Sanjivani


 

Updated On 11 Jan 2010