Tuesday, 30 August 2011

How to find second maximum value from a table?

1. select * from myTable WHERE myId = (SELECT  MAX(myId-1) FROM myTable)
2. select  MAX(myId-1) from myTable
3. select * from myTable where myId=(select max(myId) from myTable where myId<(select max(myId)
    from myTable))

Tuesday, 23 August 2011

The jQuery html() method works for both HTML and XML documents?

No ! It only works for HTML.

What are jQuery Selectors?

Selectors are used in jQuery to find out DOM elements. Selectors can find the elements via ID, CSS, Element name and hierarchical position of the element.

Why jQuery?

There are many following functionality.
       1. Cross-browser support (IE, Safari, Opera,Chrome,Firefox)
       2. AJAX functions
       3. CSS functions
       4. DOM manipulation
       5. DOM transversal
       6. Attribute manipulation
       7. Event detection and handling
       8. JavaScript animation
       9. Hundreds of plug-ins for pre-built user interfaces, advanced animations, form validation etc.
       10. Expandable functionality using custom plug-ins

What is jQuery?

JQuery is Lightweight and CrossBrowser JavaScript Library/Framework which helps in to traverse HTML DOM, make animations, add Ajax interaction, manipulate the page content, change the style and provide cool UI effect. The biggest advantage over Javascript is that it reduces lines of code as huge code written in JavaScript, can be done easily acheived with jQuery in few lines.

Saturday, 20 August 2011

How to create csv file in dot Net ?

 string filename = "";
            //----------------- File Name ----------
            string Day = DateTime.Now.Day.ToString();
            string Month = DateTime.Now.ToString("MMM");
            string Year = DateTime.Now.Year.ToString();
            string Hour = DateTime.Now.Hour.ToString();
            string Minute = DateTime.Now.Minute.ToString();
            string Second = DateTime.Now.Second.ToString();
            string strName = Day + "_" + Month + "_" + Year + "__" + Hour + "_" + Minute + "_" + Second + ".xls";
            filename = Server.MapPath("~/XLSFiles/" + strName);
            Session["AttachedFileName"] = filename;
            //--------------------------------------
            try
            {
                string sTableStart = @"<HTML><BODY><TABLE Border=1>";
                string sTableEnd = @"</TABLE></BODY></HTML>";
                StringBuilder sTableData = new StringBuilder();
                //----XLS Column Headings---------
                string sTHead = "<TR>";
                sTHead += @"<TH>S.No</TH>";
                sTHead += @"<TH>Name</TH>";
                sTHead += @"<TH>DOB</TH>";
                sTHead += @"<TH>App.Date</TH>";
                sTHead += @"<TH>Type</TH>";
                sTHead += @"<TH>Status</TH>";
                sTHead += @"</TR>";
                //------------- XLS Row asign ---------
                int SNOCounter = 1;
                string[] outerArray = hiddenIGAppointmentValuePair.Value.Split(':');
                for (int j = 0; j < gridAppointments.Rows.Count; j++)
                {
                    string[] innerArray = outerArray[j].Split(';');
                    if (innerArray[1].ToString() == "1")
                    {
                        sTableData.Append(@"<TR>");
                        sTableData.Append(@"<TD>" + SNOCounter.ToString() + @"</TD>"); // SNo
                        sTableData.Append(@"<TD>" + gridAppointments.Rows[j].Items[3].Text + @"</TD>"); // Name
                        sTableData.Append(@"<TD>" + gridAppointments.Rows[j].Items[4].Text + @"</TD>"); // DOB
                        sTableData.Append(@"<TD>" + gridAppointments.Rows[j].Items[5].Text + @"</TD>"); // AppDate
                        sTableData.Append(@"<TD>" + gridAppointments.Rows[j].Items[6].Text + @"</TD>"); // Type
                        sTableData.Append(@"<TD>" + gridAppointments.Rows[j].Items[7].Text + @"</TD>"); // Status
                        sTableData.Append(@"</TR>");
                        SNOCounter += 1;
                    }
                }
                //-------------------------------------
                string sTable = sTableStart + sTHead + sTableData.ToString() + sTableEnd;
                System.IO.StreamWriter oExcelWriter = System.IO.File.CreateText(filename);
                oExcelWriter.WriteLine(sTable);
                oExcelWriter.Close();
            }
            catch
            {
            }

Friday, 19 August 2011

How to disable/enable all constraints and triggers for database?

To disable all constraints and triggers:
sp_msforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'
sp_msforeachtable 'ALTER TABLE ? DISABLE TRIGGER  all'
To enable all constraints and triggers:
exec sp_msforeachtable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all'
sp_msforeachtable
'ALTER TABLE ? ENABLE TRIGGER  all'