MANU BAR

banner image
banner image

database connectivity in asp.net using ms access

Database connectivity in asp.net using ms access 

A) Create Database : Customer
B) Create Table : cust



C) Design Form:-

Like

हमनेे एक Table Create की हैै तथा Four Textbox, Four Button and Two Label लिए  हैै।     

D) Project File पर Right Click कर Add ASP.NET Folder ==> App_Data पर क्लिक करतेे है इस प्रकार हम Project के अंदर App_Data Folder Add कर सकते है।    


E) इसके बाद हम Database File को App_Data Folder के अंदर Add करते है। 





D) इसके बाद हमें Buttons पर Coding करेगें 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;       // adding namespace

using System.Data.OleDb; // Adding namespace

 

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

{

    public OleDbConnection con; // declare public variable con

    public OleDbDataAdapter dad;  // declare public variable dad

    public OleDbCommand com;   // declare public variable com

    public DataSet ds;  // declare public variable ds

   

    //Code for Search Data

    protected void Button3_Click(object sender, EventArgs e)

    {

        TextBox2.Text = "";

        TextBox3.Text = "";

        TextBox4.Text = "";

        con= new OleDbConnection ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+ Server.MapPath("~/App_Data/customer.accdb")+";Persist Security Info=True");

        con.Open();

        String data1;

        data1 ="select *from cust where cid=" +TextBox1.Text;

        dad =new OleDbDataAdapter (data1 ,con);

        ds = new DataSet();

        dad.Fill(ds);

        if( ds.Tables[0].Rows.Count>=1)

        {

          Label2.Text="Record Found";

          TextBox2.Text=ds.Tables[0].Rows[0]["name"].ToString();

          TextBox3.Text=ds.Tables[0].Rows[0]["course"].ToString();

          TextBox4.Text=ds.Tables[0].Rows[0]["contact"].ToString();

        }

        else

        {

        Label1.Text="Record Not Found";

         }

        con.Close ();

         }

    // Code For update Data

    protected void Button2_Click(object sender, EventArgs e)

    {

        con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/App_Data/customer.accdb") + ";Persist Security Info=True");

        con.Open();

        String data1;

        data1 ="update cust set name='"+TextBox2.Text+"',course='"+TextBox3.Text+"',contact='"+TextBox4.Text+"' where cid="+TextBox1.Text;

        com = new OleDbCommand(data1, con);

        com.ExecuteNonQuery();

        Label1.Text = "Data has been Updated";

        TextBox2.Text = "";

        TextBox3.Text = "";

        TextBox4.Text = "";

    }

    // Code for Inert Data

    protected void Button1_Click(object sender, EventArgs e)

    {

        con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/App_Data/customer.accdb") + ";Persist Security Info=True");

        con.Open();

        String data1;

        data1 ="insert into cust values("+TextBox1.Text+",'"+TextBox2.Text+"','"+TextBox3.Text+"','"+TextBox4.Text+"')";

        com=new OleDbCommand (data1 ,con);

        com.ExecuteNonQuery ();

        con.Close();

        Label1.Text="Insert Data Successfully";

        TextBox2.Text = "";

        TextBox3.Text = "";

        TextBox4.Text = "";

 

    }

    // Code for Delete Data From Database table

    protected void Button4_Click(object sender, EventArgs e)

    {

 

    con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Server.MapPath("~/App_Data/customer.accdb") + ";Persist Security Info=True");

        con.Open();

        String data1;

        data1 = "delete from cust where cid=" + TextBox1.Text;

        com=new OleDbCommand (data1 ,con);

        com.ExecuteNonQuery ();

        con.Close();

        Label1.Text="Delete Data Successfully";

        TextBox2.Text = "";

        TextBox3.Text = "";

        TextBox4.Text = "";

}

}

Download source Code:(database connectivity in asp.net using ms access) 

 --------------------------------------------------------------------------------------------------------------

Download Now

 --------------------------------------------------------------------------------------------------------------


database connectivity in asp.net using ms access database connectivity in asp.net using ms access Reviewed by JOB ORIENTED STUDY ACADEMY on October 08, 2020 Rating: 5

No comments:

Powered by Blogger.