Wednesday, 30 October 2013

How to Check Duplicate Item Names in Data Grid

void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
    if (e.ColumnIndex == dataGridView1.Columns["MyCombo"].Index)
    {
        var query = from DataGridViewRow row in dataGridView1.Rows
                    where row.Cells[e.ColumnIndex].Value != null && row.Cells[e.ColumnIndex].Value.ToString() == e.FormattedValue.ToString()
                    where row.Index != e.RowIndex
                    select row;

        if (query.Any())
        {
            MessageBox.Show(string.Format("{0} already exists", e.FormattedValue.ToString()));
            e.Cancel = true;
        }
    }
}

Tuesday, 29 October 2013

Print Page margin Setup in RDLC Reports...

 PageSettings ps = new PageSettings(); //Declare a new PageSettings for printing
                    ps.Landscape = false; //Set True for landscape, False for Portrait
                    ps.Margins = new Margins(47, 43, 149, 1); //Set margins
                    //Choose paper size from the paper sizes defined in ur printer.
                    //Here we use Linq to quickly choose by name

                    ps.PaperSize =
                        (from PaperSize p
                        in ps.PrinterSettings.PaperSizes
                         where p.PaperName == "Legal"
                         select p).First();
                    //Alternatively you can set the paper size as custom
                    //ps.PaperSize = new PaperSize("MyPaperSize", 100, 100);

                    reportViewer1.SetPageSettings(ps);




Report Dynamic File name while saving into PDF/word/excel



this.reportViewer1.LocalReport.DisplayName = "Report Name";

Friday, 18 October 2013

SQL SERVER – Count Duplicate Records – Rows




SQL SERVER – Count Duplicate Records – Rows


In my previous article SQL SERVER – Delete Duplicate Records – Rows, we have seen how we can delete all the duplicate records in one simple query. In this article we will see how to find count of all the duplicate records in the table. Following query demonstrates usage of GROUP BY, HAVING, ORDER BY in one query and returns the results with duplicate column and its count in descending order.


SELECT YourColumn, COUNT(*) TotalCountFROM YourTable 
GROUP BY YourColumnHAVING COUNT(*) > 1 
ORDER BY COUNT(*) DESC

SQL SERVER – Disk Space Monitoring – Detecting Low Disk Space on Server

CREATE PROCEDURE [CSMSDVLP].[DiskSpaceMonitor] @mailProfile nvarchar(500), @mailto nvarchar(4000), @threshold INT, @logfile nvarchar(40...