Tuesday, 19 November 2013

How to Create Table and Copying Structure of Existing Table

Create Table and Copying Structure of Existing Table
=====================================
Ex:-select * into empnew from employee where 1=0

Create Table and Copying Structure of Existing Table with data of existing table
=====================================
Ex:-select * into empnew from employee

Monday, 28 October 2013

launch sqlserver, MicroSoft visual studio, Remote login, iis from run command.

SQL Server 2005:

To launch SQL Server Management Studio 2005 from Run Command
Click Start  > Run  > sqlwb.exe


 ============================

SQL Server 2008/2012:
To launch SQL Server Management Studio 2008 or SQL Server Management Studio 2012 from Run Command
Click Start  > Run  > SSMS.exe





 ============================
 MicroSoft Visual Studio:

To launch MicroSoft Visual Studio from Run Command
Click Start  > Run  > devenv

 ============================
  Remote Login:
To launch Reomote Login from Run Command
click start > Run > mstsc

 ============================
 
  IIS Admin:
To launch IIS Admin from Run Command
click start > Run > inetmgr
 ============================  

Friday, 25 October 2013

URL Writting rule Example

              URL Writting rule Example:===

           example:---

         1.  redirect  store/plpcategory.aspx?cat=xyz   to    /xyz
          then
          2. rewrite /xyz to   store/plpcategory.aspx?cat=xyz
          


       1st step.

               <rule name="plpcategoryUserFriendlyURL1" stopProcessing="true">
                    <match url="^store/plpcategory\.aspx$" />
                    <conditions>
                        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
                        <add input="{QUERY_STRING}" pattern="^cat=([^=&amp;]+)$" />
                    </conditions>
                    <action type="Redirect" url="{C:1}" appendQueryString="false" />
                </rule>




=================================================================

      2nd step.


                <rule name="itemsRewriteUserFriendlyURL1" stopProcessing="true">
                    <match url="^([^/]+)/?$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="false" />
                        <add input="{REQUEST_URI}" pattern="^/(online|events|global|fabrics|fashion|community|embroidery|promotions|testimonials|store|shop|secure|account|pay|controls|help|pages|xml|accessories|dberror|images|include|instore|masters)" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="store/plpcategory.aspx?cat={R:1}" />
                </rule>

Tuesday, 15 October 2013

Create connection file and fill datatable with data in asp.net

 Create connection file and fill data table with data:-----------


 file name : DataAccess.cs
 ======================


using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;

namespace DataAccessNamespace
{
    /// <summary>
    /// Summary description for DataAccess
    /// </summary>

    public class DataAccess
    {
        //Variables & public properties ***********************************
        private string connectionString = "";
        private int recordCount = -1;

        /// <summary>
        /// Property: gets count of records retrieved or changed
        /// </summary>
        public int Count
        {
            get
            {
                return recordCount;
            }
        }

        //Class constructor is executed when object is initialized ***********
        /// <summary>
        /// Connection string name in web.config file is required to initialize DataAccess
        /// </summary>
        /// <param name="ConnectionName">Name of web.config connection string</param>
        public DataAccess()
        {
            //if (WebConfigurationManager.ConnectionStrings[ConnectionName] == null)
            //{
            //    throw new Exception("Cannot find connection string named '" +
            //       ConnectionName + "' in web.config");
            //}
            //Get connection string from web.config.
            //connectionString = WebConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString;
            connectionString = @"Data Source=USF142\SQLEXPRESS;Initial Catalog=demo;Integrated Security=True;";
        }
        /// <summary>
        /// Executes SELECT statement and returns results in dataTable
        /// </summary>
        /// <param name="SQL">Select SQL statement</param>
        /// <returns></returns>
        public DataTable FillDataTable(string SQL)
        {
            SqlConnection _objConn = new SqlConnection(connectionString);
            SqlDataAdapter objAdapter = new SqlDataAdapter(SQL, _objConn);
            DataTable dt = new DataTable();
            try
            {
                objAdapter.Fill(dt);
            }
            catch (SqlException ex)
            {
                throw new Exception("Error in SQL:" + SQL, ex);
            }
            catch (Exception ex)
            {
                throw ex; //Bubbling exception up to parent class
            }
            finally
            {
                _objConn.Close();
            }

            recordCount = dt.Rows.Count;
            return dt;
        }

        /// <summary>
        /// Executes "non-query" SQL statements (insert, update, delete)
        /// </summary>
        /// <param name="SQL">insert, update or delete</param>
        /// <returns>Number of records affected</returns>
        public int ExecuteNonQuery(string SQL)
        {
            SqlConnection _objConn = new SqlConnection(connectionString);
            try
            {
                _objConn.Open();
                SqlCommand objCmd = new SqlCommand(SQL, _objConn);
                recordCount = objCmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                throw new Exception("Error in SQL:" + SQL, ex);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message); //Rethrowing exception up to parent class
            }
            finally { _objConn.Close(); }

            return recordCount;
        }

        public int ExecuteScalar(String SQL)
        {
            SqlConnection _objConn = new SqlConnection(connectionString);
            int intID;
            try
            {
                _objConn.Open();
                SqlCommand objCmd = new SqlCommand(SQL, _objConn);
                intID = Convert.ToInt32(objCmd.ExecuteScalar());
            }
            catch (SqlException ex)
            {
                throw new Exception("Error in SQL:" + SQL, ex);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message); //Rethrowing exception up to parent class
            }
            finally { _objConn.Close(); }
            return intID;
        }


    }
}

==============================
create Default2.aspx+cs file

aspx.cs file


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DataAccessNamespace;
public partial class demo_Default2 : System.Web.UI.Page
{
   
    protected void Page_Load(object sender, EventArgs e)
    { 

     
        DataAccess myDA = new DataAccess();

        //Populate dataTable and bind to GridView Control
        string strSQL = "Select * from employee";

        GridView1.DataSource = myDA.FillDataTable(strSQL);
        GridView1.DataBind();
    }
}

.aspx file:-----------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="demo_Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" >
        </asp:GridView>
     
    </div>
    </form>
</body>
</html>



Saturday, 12 October 2013

C# Delegates

 A Simple Example of Delegates

 
 
using System;
public class Test
 {
  public delegate int CalculationHandler(int x, int y);
  static void Main(string[]  args)
   {
     Math math = new Math();
    //create a new instance of the delegate class

     CalculationHandler sumHandler = new CalculationHandler(math.Sum);
    //invoke the delegate
      int result = sumHandler(8,9);
     Console.WriteLine("Result is: " + result);
     }
   }

 public class Math
  {
    public int Sum(int x, int y)
     {
       return x + y;
     }
  }

Wednesday, 9 October 2013

Authentication through web.config in ASP.net 3.5


 add this on web.config file.

<authentication mode="Forms">

        <forms loginUrl="default.aspx">

          <credentials passwordFormat="Clear">

            <user name="a" password="b" />

            <user name="c" password="d" />

          </credentials>

        </forms>

      </authentication>

=======================

 <h3>Login</h3>

  <asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />

  Username: <asp:Textbox id="UsernameTextbox" runat="server" /><br />
  Password: <asp:Textbox id="PasswordTextbox" runat="server" TextMode="Password" /><br />

  <asp:Button id="LoginButton" Text="Login" OnClick="Login_OnClick" runat="server" />


========================

public void Login_OnClick(object sender, EventArgs args)
    {
        if (FormsAuthentication.Authenticate(UsernameTextbox.Text, PasswordTextbox.Text))
            Msg.Text = "done";
        else
            Msg.Text = "Login failed. Please check your user name and password and try again.";
    }






use of output parameter in sql sever


--use of output parameter in sql sever


create procedure contEmp
@count varchar(50) output
as
select @count=count(employee_id) from employee

-----------------------------
 declare @count varchar(50)
 exec contEmp @count output
 select @count

-------------------------------------------

रूस-यूक्रेन संकट लाइव: भारतीयों को 'उपलब्ध किसी भी साधन' के माध्यम से कीव को तत्काल छोड़ने के लिए कहा

  रूस यूक्रेन संकट लाइव: कीव में भारतीय दूतावास ने मंगलवार को जारी एक एडवाइजरी में भारतीयों को  'किसी भी उपलब्ध साधन' के माध्यम से क...