Friday, October 3, 2008

LINQ Simple Example

LinQ Simple Select 

 var q = from image in db.ImageDatas     // The db name is Always in Plural
                select image.Name +   "  "   + image.Caption;

        foreach (var i in q)
        {
            Response.Write(i+"
");
        }


LinQ Select With Where Clause

 var q = from image in db.ImageDatas 
                where (image.Title=="test")
                select image.Name +   "  "   + image.Caption;

        foreach (var i in q)
        {
            Response.Write(i+"
");
        }


Thanks,
Nitin Sharma
        

Sparse Columns in Sql Server 2008


One of the major enhancements in database engine of SQL Server 2008 is Sparse column. It improves data retrieval and reduces the storage cost. It also can be used with Filtered Index to improve the performance.

Sparse columns are ordinary columns that have an optimized storage for null values. Sparse columns reduce the space requirements for null values at the cost of more overhead to retrieve non-null values. Consider using sparse columns when the space saved is at least 20 percent to 40 percent. Sparse columns and column sets are defined by using the CREATE TABLE or ALTER TABLE statements.


Say you have 70,00 records in a particular Table, out which say 50,000 can remain NULL as you know.
So now it will take the space for whole 70000 record. What if the table saves this space?.this is where Sparse Coluns comes in the role.



How to create sparse column? 
Simple , just mention sparse keyword in table creation or alter statement.

CREATE TABLE TestSparseColumn
(Comments varchar(max) SPARSE null)


Summary

Using sparse columns is a good way to reduce physical storage. This feature will be useful in following scenarios

  • Storage space is a critical criteria (with sparse columns the disk space can be saved from 20 to 40 %)
  • If there are a lot of columns in a table which are likely to have NULL values (more than 50%)


Thanks,
Nitin Sharma

Wednesday, October 1, 2008

Catch the Cell value in Row_Updating in Gridview

This for only in Bound fields: 

DataControlFieldCell cell = gvUser.Rows[e.RowIndex].Cells[1] as DataControlFieldCell;
        gvUser.Columns[1].ExtractValuesFromCell(e.NewValues, cell, DataControlRowState.Edit, true);
        foreach (string key in e.NewValues.Keys)
        {
            EditUserMail(e.NewValues[key].ToString());
        }

Inline:

  asp:BoundField DataField="Email" HeaderText="Email"

Where EditUserMail can be any function.





This is for Template fields:


TextBox txtDate = (TextBox)gvUser.Rows[e.RowIndex].FindControl("txtDate");
        EditApprovedDate(txtDate.Text);

 asp:TemplateField HeaderText="Approved Till"

                ItemTemplate
                    asp:Label ID="Label1" runat="server" Text='%# Eval("Comment") %
asp:Label

                
ItemTemplate

           
EditItemTemplate

           
asp:TextBox ID="txtDate" Text=
%#Eval("Comment") %
runat="server"


asp:TextBox

        
cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtDate"
                 Animated="true" PopupPosition="Right" FirstDayOfWeek="Monday"

          
cc1:CalendarExtender

              
           EditItemTemplate
            

asp:TemplateField
              
            
            


Where EditApprovedDate can be any Function.


Thanks,
Nitin Sharma