using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
OleDbDataAdapter da;
DataSet ds;
protected void Insert_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Learning2\\App_Data\\tahir.accdb;Persist Security Info=False;");
OleDbCommand comm = new OleDbCommand("INSERT INTO test VALUES(@roll_no, @st_name, @st_course)", conn);
comm.Parameters.AddWithValue("@roll_no", TextBox1.Text);
comm.Parameters.AddWithValue("@st_name", TextBox2.Text);
comm.Parameters.AddWithValue("@st_course", TextBox3.Text);
//ds = new DataSet();
//da = new OleDbDataAdapter(comm);
//da.Fill(ds);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
}
protected void Delete_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Learning2\\App_Data\\tahir.accdb;Persist Security Info=False;");
OleDbCommand comm = new OleDbCommand("delete * from test where roll_no=@rollno ", conn);
comm.Parameters.AddWithValue("@rollno", TextBox1.Text);
conn.Open();
comm.ExecuteNonQuery();
}
protected void Update_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Learning2\\App_Data\\tahir.accdb;Persist Security Info=False;");
OleDbCommand comm = new OleDbCommand("update test set st_name='Tahir' where roll_no=@rollno ", conn);
comm.Parameters.AddWithValue("@rollno", TextBox1.Text);
conn.Open();
comm.ExecuteNonQuery();
}
protected void Display_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Learning2\\App_Data\\tahir.accdb;Persist Security Info=False;");
OleDbCommand comm = new OleDbCommand("select * from test where roll_no=@rollno ", conn);
comm.Parameters.AddWithValue("@rollno",TextBox1.Text);
da = new OleDbDataAdapter(comm);
ds = new DataSet();
da.Fill(ds);
// GridView1.DataSource = ds;
// GridView1.DataBind();
// GridView1.Visible = true;
TextBox2.Text = ds.Tables[0].Rows[0][1].ToString();
TextBox3.Text = ds.Tables[0].Rows[0][2].ToString();
da.Fill(ds);
}
}
No comments:
Post a Comment