Posts

Showing posts from August, 2017

Find Label Control In Listview asp.net c#

< asp : ListView ID ="ListView1" runat ="server" OnItemDataBound ="databound_ListView1" > < ItemTemplate > < asp : Label ID ="lbldatetime" runat ="server" text =' <% # Eval("DateTime") %> '></ asp : Label > </ ItemTemplate > </ asp : ListView > protected void databound_ListView1( object sender, ListViewItemEventArgs e)         {             Label dt;             if (e.Item.ItemType == ListViewItemType .DataItem)             {                 dt = ( Label )e.Item.FindControl( "lbldatetime" );                 DateTime date = Convert .ToDateTime(dt.Text);                 string b = "Review";                 dt.Text = b;             }         }

Time Ago in asp.net c#

Image
TimeAgo Like facebook using asp.net c# . Displaying date in timeago format under Listivew in Label control. Below is the code:    < asp : ListView ID ="ListView1" ClientIDMode ="Static" runat ="server" OnItemDataBound ="databound_ListView1" > < ItemTemplate >         < div class ="col-sm-12">     < span class ="hidden"> <% # Eval( "id" ) %> </ span >      < b > <% # Eval( "Name" ) %> </ b >      < asp : Label ID ="lbldatetime" runat ="server" text =' <% # Eval("DateTime") %> '></ asp : Label >     </ div >      </ ItemTemplate > </ asp : ListView > aspx.cs code public static string TimeAgo( DateTime date)         {             TimeSpan timeSince = DateTime .Now.Subtract(date);             if (timeSince.TotalMi

insert data into database in asp.net c#

Here is the simple insert query to insert data into database using mssql server. protected void Button1_Click( object sender, EventArgs e)         {             string constr = ConfigurationManager .ConnectionStrings[ "ApplicationServices" ].ConnectionString;             SqlConnection con = new SqlConnection (constr);             SqlCommand cmd = new SqlCommand ( "insert into tbl_view values(@Name,@EmailID,@view,@Activity,@DateTime)" );             cmd.CommandType = CommandType .Text;   

how to insert datetime in database in asp.net c#

Insert date time in database using datetime.now you can see the line of code. cmd.Parameters.AddWithValue("@DateTime", DateTime.Now);

Like Operator In Sql Server

Like operator used in where clause it’s use to search exact word from table. There are two wildcards in Like operator. _  - Underscore perform a single character % - Percent sign Perform for zero, multiple and for one character  Note: You can mix underscore and percent in query Like Operator Example Example 1 SELECT  *  FROM  Employee WHERE  Emp_Name  LIKE   'T%' ; [The following query returns all data where Emp_name starts with T] Example 2 SELECT  *  FROM  Employee WHERE  Emp_Name  LIKE   'a%i' ; [The following query selects al data and where Emp_Name starts with A and ends with I] Example 3 SELECT  *  FROM  Employee WHERE  Emp_Name  LIKE   '%T' ; [The following query returns all data with Emp_name where all Employee Name end with T] Example 4 SELECT  *  FROM  Employee WHERE  Emp_Name  LIKE   '%or%' ; [Following query returns all data where (or) will be situated in any Employee Name] Example 5

Select distinct value from data table in SQL

SELECT DISTINCT query is used to return different values from data table. In database there are so many duplicate values and if you want to select only different data and row from table use distinct statement. SELECT DISTINCT QUERY SELECT   DISTINCT   Emp_name ,  Emp_City, FROM  your_ table_name ; Now will show you the difference between SELECT and SELECT DISTINCT  SELECT Example Following Sql Query select all duplicate rows from column Emp_name from table SELECT   Emp_name FROM  Employee_table; SELECT DISTINCT Example Following Sql query select only distinct value from column Emp_name From Employee_table SELECT DITINCT   Emp_name FROM  Employee_table; Example Following SQL query selects and counts the different rows SELECT   COUNT ( DISTINCT   Emp_name )  FROM  Employee_table;