Database Connectivity Using Class and Sql Server Database in asp.net





Database Name:-   Simple  Table :- ProductTable 
 

 


Default.aspx Code:-
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;
public partial class _Default : System.Web.UI.Page
{
    protected voidPage_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ShowGrid();
        }  }

     void ShowGrid()
    {
        ClsShoping obj = newClsShoping();
        DataSet ds = new DataSet();           ds = obj.ReturnDs("Select *from ProductTable");
        GridView1.DataSource = ds.Tables[0];  GridView1.DataBind();
    }
    protected voidInsertButton2_Click(object sender, EventArgs e)
    {
        String InsertCmd = "Insert Into ProductTable (ProductName,ProductImage,Remarks) Values('" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "')";
        Response.Write(InsertCmd);        ClsShoping obj = newClsShoping();
        int x = obj.ForQuery(InsertCmd);  Response.Write("insert Record" + x);
    }
    protected void UploadButton1_Click(object sender, EventArgse)
    {
        TextBox3.Text = "~/Images/"+ FileUpload1.FileName;
        FileUpload1.SaveAs(Server.MapPath(TextBox3.Text));
        Image1.ImageUrl = TextBox3.Text;

    }
    protected voidDeleteButton4_Click(object sender, EventArgs e)
    {
        String deleteCmd = "delete from ProductTable where ProductId="+TextBox1.Text;
        Response.Write(deleteCmd);               ClsShoping obj = new ClsShoping();
        int x = obj.ForQuery(deleteCmd);         Response.Write("Delete Record" + x);
    }
    protected voidupdateButton3_Click(object sender, EventArgs e)
    {
        String updatecmd = "Update ProductTable set ProductName='" + TextBox2.Text + "',ProductImage='" + TextBox3.Text + "',Remarks='" + TextBox4.Text + "' where ProductId="+TextBox1.Text;
        Response.Write(updatecmd);          ClsShoping obj = new ClsShoping();
        int x = obj.ForQuery(updatecmd);    Response.Write("update  Record" + x);
    }
    protected voidRefreshGridButton6_Click(object sender, EventArgs e)
    {       ShowGrid();      }
    protected voidSearchButton5_Click(object sender, EventArgs e)
    {
        String searchcmd = "select *from ProductTable where ProductId=" + TextBox1.Text;
        ClsShoping obj = newClsShoping();        DataSetds = new DataSet();
        ds = obj.ReturnDs(searchcmd);             GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
    } }

 











Comments

Popular posts from this blog

Creating a DDL File & link ddl file in C#

SQL Command in asp.net