Complete Databaes only Save, Insert in asp.net









 
using System;

usingSystem.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

usingSystem.Data.SqlClient;

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(objectsender, EventArgs e)

    {



    }

    protected void Button1_Click(objectsender, EventArgs e)

    {

        TextBox5.Text = "~/Images/"+ FileUpload1.FileName;

        FileUpload1.SaveAs(Server.MapPath(TextBox5.Text));

        Image1.ImageUrl = TextBox5.Text;



    }

    protected void Button2_Click(objectsender, EventArgs e)

    {

        SqlConnectioncon=new SqlConnection(@"Data Source=CHAINSINGH-PC\SQLEXPRESS;Initial Catalog=Simple;Integrated Security=True");

        con.Open();

        stringstrInsert="insert into Contact (First_Name,Last_Name,Mobile_No,Photo) values('"+TextBox2.Text+"','"+TextBox3.Text+"','"+TextBox4.Text+"','"+TextBox5.Text+"')";

        SqlCommandcmd = new SqlCommand(strInsert, con);

        int x = cmd.ExecuteNonQuery();

        Response.Write("Save Data"+x);

    }

}
 






Search Button Code:-

protected void Button3_Click(objectsender, EventArgs e)

    {

        SqlConnectioncon = new SqlConnection(@"Data Source=CHAINSINGH-PC\SQLEXPRESS;Initial Catalog=Simple;Integrated Security=True");

        con.Open();

        stringSearchResult = "select  First_Name,Last_Name,Mobile_No,Photo from Contact where Id="+TextBox1.Text+"";

        SqlCommandcmd = new SqlCommand(SearchResult, con);

        SqlDataReaderSQLDR = cmd.ExecuteReader();

        while(SQLDR.Read())

        {

            TextBox2.Text = Convert.ToString(SQLDR["First_Name"]);

            TextBox3.Text = Convert.ToString(SQLDR["Last_Name"]);

            TextBox4.Text = Convert.ToString(SQLDR["Mobile_No"]);

            TextBox5.Text = Convert.ToString(SQLDR["Photo"]);

            Image1.ImageUrl = TextBox5.Text;

        }

    }



Update Command code:-



protected void Button5_Click(objectsender, EventArgs e)

    {

        SqlConnectioncon = new SqlConnection(@"Data Source=CHAINSINGH-PC\SQLEXPRESS;Initial Catalog=Simple;Integrated Security=True");

        con.Open();

        stringUpdate = "update Contact set First_Name='" + TextBox2.Text + "',Last_Name='"+ TextBox3.Text + "', Mobile_No='"+ TextBox4.Text + "',Photo='" + TextBox5.Text + "' where Id="+ TextBox1.Text +"";

        SqlCommandcmd = new SqlCommand(Update, con);

        int x = cmd.ExecuteNonQuery();

        Response.Write("Update Data Successfully" + x);

    }








Comments

Popular posts from this blog

Creating a DDL File & link ddl file in C#

SQL Command in asp.net