Pages

Saturday, November 9, 2013

CSS to Blink the text

.blink
{
  1. -webkit-animation-nameblinker;
  2. -webkit-animation-iteration-count:infinite;
  1. -webkit-animation-timing-function:cubic-bezier(.5, 0, 1, 1);
  1. -webkit-animation-duration5.0s;
}



apply:

<span style="padding-left:40px;" class="blink">ANKIT</span>

Thursday, November 7, 2013

Get Day,month,year from Date using datepart( ) Function in SQL Server


Use this function to get the Year of current Date:
datepart(yy,date)

Use this function to get the month of current Date:
datepart(mm,date)

Use this function to get the day of current Date:
datepart(dd,date)


Ex:

Select Datepart(dd,admissiondate) from Student;

This print the day of the date in the  'admissiondate' column

Thursday, October 10, 2013

Create SQL Table Dynamically using C#


Use this code to create table dynamically in the SQL server,


SqlConnection con = new SqlConnection("Data Source=yourservername;Initial Catalog=yourdatabase;Integrated Security=True");
SqlCommand com = new SqlCommand();
con.Open();
com.Connection = con;
com.CommandText = "Create table dyTab(id int,name varchar(100),age int)";
com.ExecuteNonQuery();
con.Close();


Here 'dyTab' is the Table Name
yourservername will be replaced by your server name
yourdatabase will be replaced by your database name

Create SQL Database Dynamically using C# code

Use below Code to Create SQL Database and create .mdf and .ldf file to your desired location :

Note: In the connection string , Initial Catalog should be 'master'

'myDB' will be by any name , which u want to like as database name.



SqlConnection con = new SqlConnection("Data Source=yourservername;Initial Catalog=master;Integrated Security=True");
SqlCommand com = new SqlCommand();

string db_str = "CREATE DATABASE myDB ON PRIMARY " +
       "(NAME =
myDB _Data, " +
       "FILENAME = 'C:\\
myDB.mdf', " +
       "SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
       "LOG ON (NAME =
myDB _Log, " +
       "FILENAME = 'C:\\
myDB.ldf', " +
       "SIZE = 1MB, " +
       "MAXSIZE = 5MB, " +
       "FILEGROWTH = 10%)";

con.Open();com.Connection = con;
com.CommandText = db_str;
com.ExecuteNonQuery();
con.Close();


After compile this Code:

Database myDB Created to the SQL, and myDB.mdf and myDB.ldf created in the C Drive as the path given in the code.


Thursday, October 3, 2013

Random Aplhanumeric String Generator- C#

This function Returns Random Generate string ...

 private string RandomGenerator()
    {
        var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        var random = new Random();
        var result = new string(
            Enumerable.Repeat(chars, 8)
                      .Select(s => s[random.Next(s.Length)])
                      .ToArray());
        return result.ToString();
    }




Call This function:

Page_load(eve..)
{
string UserID=RandomGenerator( );
}

Thursday, September 26, 2013

REGEX to match the exact word in the string, ignoring case.



 string keyword="ankit";
 string str="my name is ankit";


 if (Regex.Match(str.Trim().ToLower(), @"\b" + keyword.Trim().ToLower() + @"\b", RegexOptions.Singleline | RegexOptions.IgnoreCase).Success)
{
      // if matches
}
else
{
     // if not matches




Here, in 'if' condition "Success" is used to the condition is true or not, just like "==true"

Split string, ignoring Case,ignoring blank values and Select Distinct split values



String str = "ankit,Ankit,ankit, , ,aNkit,rahul";

here, we have to split above string  by ','


var split_values = str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct(StringComparer.CurrentCultureIgnoreCase); 



You will get :

ankit
rahul



Tuesday, September 24, 2013

Copy unique rows of a column from one Datatable to other Datatable - LINQ



Here , We have to copy the unique rows of column 'CategoryName' from DataTable 'dt_old' to the 'Category' column of DataTable 'dt_Categories' using LINQ.


 DataTable dt_Categories = new DataTable();
 dt_Categories.Columns.Add("Category", Type.GetType("System.String"));

DataTable dt_old = new DataTable();
dt_old = (DataTable)Session["dt"];


 dt_Categories = dt_old.AsEnumerable().Select(row =>
            {
                DataRow newRow = dt_Categories.NewRow();
                newRow["Category"] = row.Field<string>("CategoryName");
                return newRow;
            }).Distinct(DataRowComparer.Default).CopyToDataTable();






Wednesday, September 18, 2013

Query to Create Dynamically com.Parameters.Add - SQL




Select +'com.Parameters.AddWithValue("@'+COLUMN_NAME+' ", dt_results.Rows[i]["'+COLUMN_NAME+'"]); ' from INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='YourTableName'


This Gives Output :

                    com.Parameters.AddWithValue("@ItemId", dt_results.Rows[i]["ItemId"]);
                    com.Parameters.AddWithValue("@GlobalId", dt_results.Rows[i]["GlobalId"]);
                    com.Parameters.AddWithValue("@ProductId", dt_results.Rows[i]["ProductId"]);
                    com.Parameters.AddWithValue("@CategoryId", dt_results.Rows[i]["CategoryId"]);
                    com.Parameters.AddWithValue("@CategoryName", dt_results.Rows[i]["CategoryName"]);
                    com.Parameters.AddWithValue("@Location", dt_results.Rows[i]["Location"]);
                    com.Parameters.AddWithValue("@PostalCode", dt_results.Rows[i]["PostalCode"]);
                    com.Parameters.AddWithValue("@Title", dt_results.Rows[i]["Title"]);
                    com.Parameters.AddWithValue("@Price", dt_results.Rows[i]["Price"]);
                    com.Parameters.AddWithValue("@SellingState", dt_results.Rows[i]["SellingState"]);
                    com.Parameters.AddWithValue("@TimeLeft", dt_results.Rows[i]["TimeLeft"]);
                    com.Parameters.AddWithValue("@ShippingType", dt_results.Rows[i]["ShippingType"]);
                    com.Parameters.AddWithValue("@Currency", dt_results.Rows[i]["Currency"]);
                    com.Parameters.AddWithValue("@ShipToLocations", dt_results.Rows[i]["ShipToLocations"]);
                    com.Parameters.AddWithValue("@HandlingTime", dt_results.Rows[i]["HandlingTime"]);


Query to Merge All Columns Separated with comma -SQL Server


This Query Gives all columns in a single column Separated with comma.

SELECT STUFF((SELECT COLUMN_NAME+',' as [text()] FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='TableName' for xml path('')),1,0,'')

You can Replace the comma with any symbol by which u want to separate.


'TableName' must be replaced by your table name.