Sunday, September 16, 2018

Database Query using Class Concept

1. Create class ( website->add new item-> class file ( .cs) )

public class Class1
{
    SqlDataReader dr;
    SqlCommand cm;
    SqlConnection cn;

public string Connection()
{
       
        string cs = @"path";
        return cs;
}


    public string querry()
    {
        string k = "select * from Table1";
        return k;
    }

    public string INSERT()
    {

        string q = "insert into Table1 values";
        return q;
    }
}



2.  How to access class file in aspx page 

protected void Button1_Click(object sender, EventArgs e)
    {
       
        Class1 MY1 = new Class1();
        string cs = MY1.Connection();
        cn = new SqlConnection(cs);
        cn.Open();

string k = MY1.INSERT()+"('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')";


        cm = new SqlCommand(k, cn);

        cm.ExecuteNonQuery();

        Response.Write("Data saved");



    }


No comments:

Post a Comment

GRIDVIEW ON ROW DATA BOUND EVENT

 Database Create  Student : roll , name , city , cost  Fix 6 Value  in Database Record  ====================================================...