Monday, February 24, 2014

ASP.NET WITH C# Solution by Arvind kumar vishwakarma..

ASP.NET WITH C#

using System;
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 System.Data.SqlClient;   --- SQL PACKAGE

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

    }
    public void update1(int id)   ----UPDATE CODEING
    {
       
     
       
       
        String constring = ConfigurationSettings.AppSettings["con"].ToString();
        SqlConnection con = new SqlConnection(constring);
        String sql = "sp_updateEndetail";
        SqlCommand cmd = new SqlCommand("sp_updateEndetail", con);
        cmd.CommandType = CommandType.StoredProcedure;
        // SqlParameter p1=new SqlParameter("@",)


        cmd.Parameters.Add("@EnqId", SqlDbType.Int).Value =id;
        cmd.Parameters.Add("@EnquiryName", SqlDbType.VarChar).Value = TxtEnm.Text;
        cmd.Parameters.Add("@EnquiryAddress", SqlDbType.VarChar).Value = TxtEadd.Text;
        cmd.Parameters.Add("@TelNo", SqlDbType.VarChar).Value = Txttel.Text;
        cmd.Parameters.Add("@Refrence", SqlDbType.VarChar).Value = Txtref.Text;
        cmd.Parameters.Add("@EnquiryDetail", SqlDbType.VarChar).Value = TxtEdetl.Text;

        con.Open();

        if (cmd.ExecuteNonQuery() > 0)
        {
            Response.Write("data update succe");
        }
        else
        {
            Response.Write("operation failed");
        }
        con.Close();
        LoadGridview();
     
     
    }
    protected void Btnsub_Click(object sender, EventArgs e)  ------------INSERT DATA
    {



        if (ViewState["Edit"] == null)
        {
            String constring = ConfigurationSettings.AppSettings["con"].ToString();
            SqlConnection con = new SqlConnection(constring);
            String sql = "sp_Enquirydetl";
            SqlCommand cmd = new SqlCommand("sp_Enquirydetl", con);
            cmd.CommandType = CommandType.StoredProcedure;
            // SqlParameter p1=new SqlParameter("@",)


            //cmd.Parameters.Add("@EnqId", SqlDbType.VarChar).Value = TxtEnm.Text;
            cmd.Parameters.Add("@EnquiryName", SqlDbType.VarChar).Value = TxtEnm.Text;
            cmd.Parameters.Add("@EnquiryAddress", SqlDbType.VarChar).Value = TxtEadd.Text;
            cmd.Parameters.Add("@TelNo", SqlDbType.VarChar).Value = Txttel.Text;
            cmd.Parameters.Add("@Refrence", SqlDbType.VarChar).Value = Txtref.Text;
            cmd.Parameters.Add("@EnquiryDetail", SqlDbType.VarChar).Value = TxtEdetl.Text;

            con.Open();
            if (cmd.ExecuteNonQuery() > 0)
            {
                Lblmsg.Text = "Data Added";

            }
            else
            {
                Lblmsg.Text = "Data not Added";

            }
            con.Close();

        }
        else
        {
            update1(Convert.ToInt32(ViewState["Edit"]));
        }
       




    }
    protected void Btnclr_Click(object sender, EventArgs e)---- CLEAR CODEING
    {
        TxtEnm.Text = "";
        TxtEadd.Text = "";
        Txttel.Text = "";
        Txtref.Text = "";
        TxtEdetl.Text = "";
    }
    protected void Btnview_Click(object sender, EventArgs e) --- SHOW GRIDVIEW DATA
    {
        LoadGridview();   ------------ METHOD CALL
    }
    private void LoadGridview()     -----------CODEIND FOR GRIDVIEW
    {
        String constring = ConfigurationSettings.AppSettings["con"].ToString();
        DataSet ds = new DataSet();
        SqlConnection con = new SqlConnection(constring);
        String sql = "select * from Endetail";
        SqlCommand cmd1 = new SqlCommand(sql, con);
        cmd1.CommandType = CommandType.Text;
        SqlDataAdapter da = new SqlDataAdapter(cmd1);
        con.Open();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        int EnqId = Convert.ToInt32(GridView1.DataKeys[e.NewEditIndex].Values[0]);
        BindData(EnqId);

    }
    public void BindData(int EnqId)   ------ DATABINDING CODEING FOR EDITING
    {

        Btnsub.Text = "update";
        String constring = ConfigurationSettings.AppSettings["con"].ToString();
        DataTable dt = new DataTable();
        SqlConnection con = new SqlConnection(constring);
        String sql = "select * from Endetail where EnqId="+EnqId+"" ;
        SqlCommand cmd1 = new SqlCommand(sql, con);
        cmd1.CommandType = CommandType.Text;
        SqlDataAdapter da = new SqlDataAdapter(cmd1);
        con.Open();
        da.Fill(dt);
       
        if (dt.Rows.Count >0)
        {
            TxtEnm.Text=dt.Rows[0]["EnquiryName"].ToString();
            Txttel.Text = dt.Rows[0]["TelNo"].ToString();
            TxtEadd .Text = dt.Rows[0]["EnquiryAddress"].ToString();
            Txtref .Text = dt.Rows[0]["Refrence"].ToString();
            TxtEdetl.Text = dt.Rows[0]["EnquiryDetail"].ToString();
            Lblid.Text = dt.Rows[0]["EnqId"].ToString();
            ViewState["Edit"] = dt.Rows[0]["EnqId"].ToString(); ;
        }

    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int EnqId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]);
        delete1(EnqId);
    }

    public void delete1(int id)---------DELETEING
    {
        String constring = ConfigurationSettings.AppSettings["con"].ToString();
        SqlConnection con = new SqlConnection(constring);
        String sql = "sp_deleteEndetail";
        SqlCommand cmd = new SqlCommand(sql, con);
        cmd.CommandType = CommandType.StoredProcedure;
        // SqlParameter p1=new SqlParameter("@",)


        cmd.Parameters.Add("@EnqId", SqlDbType.Int).Value = id;
         con.Open();

        if (cmd.ExecuteNonQuery() > 0)
        {
            Response.Write("data delete succe");
        }
        else
        {
            Response.Write("operation failed");
        }
        con.Close();
        LoadGridview();

    }
}

No comments:

Post a Comment

JDBC  Connectivity With MySQL