Monday 28 September 2015

Configuration Error in SiteMap MySqlSiteMapProvider in Web.Config File Using Asp.Net

Configuration Error in SiteMap MySqlSiteMapProvider 


MySqlSitemap Remove From Web.Config File Using Asp.Net C#





Sunday 27 September 2015

How to Create Stored Procedure in Asp.Net C#

No comments    
categories: , , ,
Create Stored Procedure in Asp.Net C#

A Stored Procedure is a set of Structured Query Language  (SQL). They are stored in database server (SQL Server). Stored procedure is a group of T-SQL statements which performs one or more specific task in a single execution plan.

                                 DEMO



                           Download

Insert_Sp

CREATE PROCEDURE insert_Sp
       @username varchar(50),
       @password varchar(50)
AS
begin
insert into login(username,password) values(@username,@password)

end


Select_Sp


CREATE PROCEDURE select_Sp
       @username varchar(50),
       @password varchar(50)
AS
begin
       SELECT username,password from login where username=@username and password =@password
end


Edit_Sp


CREATE PROCEDURE edit_Sp
       @password varchar(100),
       @Id int
AS
begin
       Update login set password=@password where Id=@Id
       end


Delete_Sp


CREATE PROCEDURE delete_Sp
       @Id int
AS
begin
       delete from login where Id=@Id
end


                         HTML Coding

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Create Stored Procedure in Asp.Net C#</title>
  
</head>
<body>
    <form id="form1" runat="server">
    <div align="center">

    <table>
    <tr><td colspan="2" class="auto-style1">
        <asp:Label ID="Label1" runat="server" Font-Size="Larger" ForeColor="#CC3300" Text="Stored Procedure"></asp:Label>
</td></tr><tr>
    <td>User Name: </td><td>
        <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox><br />
        </td>
    </tr>
     <tr>
    <td>Password: </td><td>
        <asp:TextBox ID="txtPwd" runat="server"></asp:TextBox>
         <br />
         </td>
    </tr><tr><td>ID<tD>
         <asp:TextBox ID="txtid" runat="server"></asp:TextBox>
            </tD></td></tr>
     <tr>
     <td></td>
    <td>
        <asp:Button ID="btnLogin" runat="server" Text="Login"
            onclick="btnLogin_Click" />&nbsp;
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Insert" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Delete" />
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click1" Text="Update" />
         </td>
    </tr>
     <tr>
     <td></td>
     <td>
         <asp:Label ID="lblMessage" runat="server" ForeColor="#FF0066"></asp:Label>
                  </td>
    </tr>
    </table>
    </div>
    </form>
</body>

</html>


                              C# Coding


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class StorasedProcedure : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
         
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbcon"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select_Sp", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@username", txtUserName.Text);
            cmd.Parameters.AddWithValue("@password", txtPwd.Text);
            DataTable dt = new DataTable();
           SqlDataAdapter adp = new SqlDataAdapter();   
            adp.SelectCommand = cmd;
            adp.Fill(dt);           
            if (dt.Rows.Count > 0)
            {
                lblMessage.Text = "Login Successfull";              
            }
            else
            {
           lblMessage.Text = "Invalid Username Or Password";               
            }
        }  
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbcon"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand("insert_Sp", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@UserName", txtUserName.Text);
        cmd.Parameters.AddWithValue("@Password", txtPwd.Text);
        cmd.ExecuteNonQuery();
        lblMessage.Text = "Insert Successfull";
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbcon"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand("delete_Sp",con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Id"Convert.ToInt32(txtid.Text));
        cmd.ExecuteNonQuery();
        lblMessage.Text = "Delete Successfully";
    }  
    protected void Button3_Click1(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbcon"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand("edit_Sp", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@password", txtPwd.Text);
        cmd.Parameters.AddWithValue("@Id"Convert.ToInt32(txtid.Text));
        lblMessage.Text = "Updated Successfully";
    }

}




















Friday 25 September 2015

Array in Asp.Net C# Examples

No comments    
categories: , ,
Array in Asp.Net C#


Single - Dimensional Array


//---- Integer Datatype Array ----//



      int[] num = new int[5];

        num[0] = 0;
        num[1] = 1;
        num[2] = 2;
        num[3] = 3;
        num[4] = 4;

      Response.Write(num[3].ToString());


 OUTPUT



      ////   -------  String Datatype Array  ----- /////


        string[] week = new string[3] { "Sun""Mon""Tus" };
        for (int i = 0; i < week.Length; i++)
        {
            Response.Write(week[i] + ",");
        }



OUTPUT

                      
////   ------- For Loop   Integer Datatype Array   ----- /////


        int[] array = new int[4] { 10, 20, 30, 40 };

        array[0] = 10;
        array[1] = 20;
        array[2] = 30;
        array[3] = 40;

        for (int i = 0; i < array.Length; i++)
        {
            Response.Write(array[i] + ",");
        }



OUTPUT

 
////   -------  Boolean Datatype Array  ----- /////


        Array a = Array.CreateInstance(typeof(int), 5);

        a.SetValue(100, 0);
        a.SetValue(109, 1);
        a.SetValue(150, 2);
        a.SetValue(250, 3);
        a.SetValue(300, 4);

        int b = 5;

        Response.Write(Convert.ToBoolean(a.Length.Equals(b).ToString()));


           OUTPUT

 


         /// --- Sorting Array   ---  ///

        int[] numbers = { 9, 1, 5, 0, 9 };

        Array.Sort(numbers);

        foreach (int i in numbers)

            Response.Write (i+",");



            OUTPUT


 


        //  Create an Array with different data types //

        object[] Mix = new object[4];
        Mix[0] = 10;
        Mix[1] = "Dotnetdrizzles";
        Mix[2] = DateTime.Now;
        Mix[3] = DateTime.Now.AddDays(1).ToString();
        for (int i = 0; i < Mix.Length; i++)
        {
            Response.Write(Mix[i] + " , ");
        }


        
             OUTPUT


 
 ////   -------  Calculation in Integer Datatype Array  ----- /////


        int[] array11 = { 10, 20, 30 };

        Response.Write(array11[1] * 5);



             OUTPUT

                  
////   ------- Index  Find  String Datatype Array  ----- /////



        string[] array2 = new string[] { "A""B""C" };

        int Getindex = Array.IndexOf(array2, "B");

        Response.Write(Getindex.ToString());


        OUTPUT


             

            
////   -------   Array  Index Length ----- /////


        string[] array3 = new string[] { "A""B""C" };

        Response.Write(array3.Length + " "); // Empty Last Index Display

        Response.Write(array3.Length - 1); // Correct Index Length Display


         OUTPUT


             

 ////   -------  Resize Array Index Char Datatype Array  ----- /////


        char[] array4 = new char[5] { 'A''B''C''D''E' };
       
        Array.Resize(ref array4, 3);

        for (int i = 0; i < array4.Length; i++)
        {
            Response.Write(array4[i].ToString()+",");
        }

           
                 OUTPUT


                
////   -------  Foreach in Integer Datatype Array  ----- /////


        int[] array5 = new int[3] { 10, 30, 50 }; //array declaration
        foreach (int element in array5)
        {
            Response.Write(element);
        }


               OUTPUT

                
 ////   ------- Finding  Array  ----- /////


        string Check = "Drizzles";
        string[] stringArray = { "Dot""Net""Drizzles" };
        foreach (string x in stringArray)
        {
            if (x.Equals(Check))
            {
                Response.Write("Finding = " + x);
            }
             else
            {
                Response.Write("Finding = Not Equal");           
            }
        }


               OUTPUT