Insert Data using Connection Class:-
on the submit button click event code for insert data using sql class connection
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 Insert : System.Web.UI.Page
{
Class1 obj = new Class1();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button3_Click(object sender, EventArgs e)
{
string str="insert into Datas(firstname,lastname,mobile) values('"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"')";
obj.savedata(str);
}
}
In this coding the Class1 obj = new Class1();
create new object of that class and we can use that class method , in our case we create two method the calldata(), and the savedata();
The calldata(); method is used to retrieve data from database and
The savadata(); method is used to execute the query
using the object of that class .