Monday, 3 December 2012

Datediff with sql server

Date-
1.       select DATEDIFF(MILLISECOND ,GETDATE()-1,GETDATE()) as milisecond


Time-

1.       select right(convert(varchar(30),getdate(),121),12)
                             outpur-- 15:02:24.3424398

2.       SELECT CONVERT(VARCHAR(16), SYSDATETIME(), 14)

                              outpur-- 15:02:24.3424398

Wednesday, 3 October 2012

Convert generic list to datatable in c#


 public class ListtoDataTableConverter
        {
            public DataTable ToDataTable<T>(List<T> items)// T is a type not a list
            {
                DataTable dataTable = new DataTable(typeof(T).Name);
                //Get all the properties
                PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
                foreach (PropertyInfo prop in Props)
                {
                    //Setting column names as Property names
                    dataTable.Columns.Add(prop.Name);
                }
                foreach (T item in items)
                {
                    var values = new object[Props.Length];
                    for (int i = 0; i < Props.Length; i++)
                    {
                        //inserting property values to datatable rows
                        values[i] = Props[i].GetValue(item, null);
                    }
                    dataTable.Rows.Add(values);
                }
                //put a breakpoint here and check datatable
                return dataTable;
            }
        }
        DataTable dtttt;
        public void pppp()
        {
            ListtoDataTableConverter converter = new ListtoDataTableConverter();
            dtttt = converter.ToDataTable(sessionuserlist);
        }

Monday, 27 August 2012

Before & after items after split a string


Before split string


       string input = TextBox1.Text;
        int index = input.LastIndexOf("@");
               or-  int index = input.IndexOf("@");
        if (index > 0)
        input = input.Substring(0, index);
        resporse.write=input;



After split strings



string input = TextBox1.Text;
        response.write = input.Split('@').Last();

Tuesday, 7 August 2012

Second highest salary

1. METHOD

select max(salary) from emp where salary not in (select max(salary) from emp )

 2. METHOD ANY SALARY-- PUT NUMBER OF COUNT IN SUB-QUERY


SELECT TOP 1 Salary FROM ( SELECT TOP 5 Salary FROM emp ORDER BY Salary DESC)TEMP ORDER BY Salary

Monday, 25 June 2012

requirefieldvalidator onclientside validator with with confirmation checkbox

 <script type="text/javascript">
        function che() {
            var ch = document.getElementById('<%=CheckBox1.ClientID %>');
            if (Page_ClientValidate()) {
                if (!ch.checked) {
                    alert("Please select checkbox first.");
                    return false;
                }
            }
        }   
    </script>

HTML-------------------------------------

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
       <asp:RequiredFieldValidator id="rq1" ControlToValidate="TextBox1" ErrorMessage="Name cannot be blank" Display="Dynamic" runat="server"/>
        <asp:CheckBox ID="CheckBox1" runat="server" />
        <asp:Button ID="Button1" runat="server" Text="Button"
            OnClientClick="return che();" onclick="Button1_Click" ValidationGroup="2" />

selecet girdview row clickon any where on row

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {                            
            e.Row.Attributes.Add("onclick",     String.Format("javascript:__doPostBack('GridView1','Select${0}')", e.Row.RowIndex));
        }
    }


 protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    { 
       string tt=((Label)GridView1.SelectedRow.Cells[1].FindControl("Label1")).Text;
         lblSelectedRow.Text = tt;               
    }

checkbox single selection with rowdatabound in girdview

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
     
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string strScript = "uncheckOthers(" + ((CheckBox)e.Row.Cells[0].FindControl("CheckBox1")).ClientID + ");";
                ((CheckBox)e.Row.Cells[0].FindControl("CheckBox1")).Attributes.Add("onclick", strScript);
            }
  }

protected void GridView1_PageIndexChanged(object sender, EventArgs e)
    {
        CheckBox ch = ((CheckBox)GridView1.SelectedRow.Cells[0].FindControl("CheckBox1"));
        ch.Checked = true;
    }
      

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...