W ) MS Access Database

                                  Access Database  *

   Step 1 :- Open Access (Microsoft access)
   Step 2 :- Select Blanck Database 
   Step 3 :- File Name (Collage.mdb)  -- select drive C ,E ,D --  remove accdb extension compulsory .mdb -- Create
   Step 4 :- left side Table -- click on table Right Click -- Desighn View -- TABLE NAME (Student )
   Step 5 :- Click on Field Name cell -- right click and deactivate Primary Key --  Column name (roll _datatype Number) (name , mobile ,city datatype Text)
  Step 6 :- Save Table -- click onn double click on table and open .
  

                              * How to Create MS access table  *



  

    MS Access Library :-  Using System.Data.OleDb ;    // Step 1

                                         OleDbConnection cn;             // S 2
                                         OleDbCommand cm;
                                        OleDbDataReader dr;

Download Ms Access PRovider on Gooogle  

   //string cs = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=DRIVE:/FILENAME.mdb";
        
        string path = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/student.mdb";  
        cn = new OleDbConnection(path);        
        cn.Open();
    //  // E is drive location / collage1.mdb FileName
Step On Ms Access Code


  
                                     *Simple Insert data in MS access in dotnet *

  

Source Code :-MSacess. ASPX 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Z1__Ms_Access.aspx.cs" Inherits="Z_1_Ms_Access" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <br />
&nbsp;&nbsp; Roll&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="txtroll" runat="server"></asp:TextBox>
        <br />
&nbsp;
        <br />
&nbsp;&nbsp; Name&nbsp;&nbsp;
        <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
        <br />
        <br />
&nbsp; Mobile&nbsp;&nbsp;
        <asp:TextBox ID="txtmobile" runat="server"></asp:TextBox>
        <br />
        <br />
&nbsp; City&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="txtcity" runat="server"></asp:TextBox>
        <br />
        <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button1" runat="server" Height="31px" onclick="Button1_Click" 
            Text="Submit" Width="74px" />
    
        <br />
        <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            Height="207px" Width="474px">
            <Columns>
                <asp:BoundField DataField="roll" HeaderText="Roll" />
                <asp:BoundField DataField="name" HeaderText="Name" />
                <asp:BoundField DataField="mobile" HeaderText="Mobile" />
                <asp:BoundField DataField="City" HeaderText="City" />
            </Columns>
        </asp:GridView>
    
    </div>
    </form>
</body>
</html>

Button Code :- MSacess. ASPX.CS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;                                      // MS ACCESS Library  Step 1

public partial class Z_1_Ms_Access : System.Web.UI.Page
{
    OleDbConnection cn;             // S 2
    OleDbCommand cm;
    OleDbDataReader dr;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)           // S3
        {
            Show();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //string cs = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=DRIVE:/FILENAME.mdb";
        
        string path = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/student.mdb";  // Access Coonection Provider Download on google
        cn = new OleDbConnection(path);                                                    // E is drive location / collage1.mdb database Name
        cn.Open();

        string k = "insert into student1 (roll,name,mobile,city)values(@roll1,@name1,@mobile1,@city1)";
        cm = new OleDbCommand(k, cn);
        cm.Parameters.AddWithValue("roll1", txtroll.Text);
        cm.Parameters.AddWithValue("name1", txtname.Text);
        cm.Parameters.AddWithValue("mobile1", txtmobile.Text);
        cm.Parameters.AddWithValue("city1", txtcity.Text);
        cm.ExecuteNonQuery();
        Response.Write("Record Submited Succesfully");
    }

    protected void Show()
    {
        string path = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/student.mdb";  
        cn = new OleDbConnection(path);                                                   
        cn.Open();

        string k = "select * from student1";
        cm = new OleDbCommand(k, cn);
        dr = cm.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();

    }
}


 Microsoft Access grid implementation

    (  Reapeater, Fomview , DataList , Detailview , Listview , StoreProcedure , Class  )

Source Code :- Gridinall.Aspx
                                            
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Z1ass_Accessinall(gridimpliment).aspx.cs" Inherits="ZZZAccessinall_gridimpliment_" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            height: 23px;
        }
        .style2
        {
            color: #FF0000;
        }
        </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<strong> 
        Microsoft Access grid implementation
        <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="style2">Reapeater, Fomview , DataList , Detailview , Listview , 
        StoreProcedure , Class </span><br />
&nbsp;<br />
&nbsp; 1 ) GRIDVIEW</strong>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            Height="279px" Width="610px">
            <Columns>
                <asp:TemplateField HeaderText="roll">
                <ItemTemplate>
                    <asp:TextBox ID="txtroll" runat="server" Text='<%# Eval("roll") %>'></asp:TextBox>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="name">
                <ItemTemplate>
                    <asp:TextBox ID="txtname" runat="server" Text='<%# Eval("name") %>'></asp:TextBox>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="mobile">
                <ItemTemplate>
                    <asp:TextBox ID="txtmobile" runat="server" Text='<%# Eval("mobile") %>'></asp:TextBox>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="city">
                <ItemTemplate>
                    <asp:TextBox ID="txtcity" runat="server" Text='<%# Eval("city") %>'></asp:TextBox>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Submit">
                <ItemTemplate>
                    <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="submit1_click" />
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Update">
                <ItemTemplate>
                    <asp:Button ID="Button2" runat="server" Text="Update" OnClick="update1_click" />
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Delete">
                <ItemTemplate>
                    <asp:Button ID="Button3" runat="server" Text="Delete" OnClick="delete1_click" />
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="show(Formview)">
                <ItemTemplate>
                    <asp:Button ID="Button4" runat="server" Text="Show" OnClick="formview1_click" />
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Datalist">
                <ItemTemplate>
                    <asp:Button ID="Button5" runat="server" Text="Datalist" OnClick="datalist1_click" />
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Reapeater">
                <ItemTemplate>
                    <asp:Button ID="Button14" runat="server" Text="Reapater" OnClick="reapeater1_click" />
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Detailview">
                <ItemTemplate>
                    <asp:Button ID="Button10" runat="server" Text="Detailview" OnClick="detailview_click" />
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Listview">
                <ItemTemplate>
                    <asp:Button ID="Button12" runat="server" Text="Listview" OnClick="listview1_click" />
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="StoreProcedure">
                <ItemTemplate>
                    <asp:Button ID="Button13" runat="server" Text="update" OnClick="update111_click" />
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="ClassObject">
                <ItemTemplate>
                    <asp:Button ID="Button15" runat="server" Text="Submit" OnClick="ClassSubmit1_click" />
                </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    
        <br />
    
        <br />
&nbsp;&nbsp; <strong>2) FORMVIEW</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;
        <asp:FormView ID="FormView1" runat="server" Height="131px" Width="201px">
            <ItemTemplate>
                &nbsp;<table style="width:100%;">
                    <tr>
                        <td>
                            Roll</td>
                        <td>
                            <%# Eval("roll") %></td>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            Name</td>
                        <td>
                            <%# Eval("name") %></td>
                        <td>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td class="style1">
                            Mobile</td>
                        <td class="style1">
                            <%# Eval("mobile") %></td>
                        <td class="style1">
                        </td>
                    </tr>
                    <tr>
                        <td class="style1">
                            City</td>
                        <td class="style1">
                            <%# Eval("city") %></td>
                        <td class="style1">
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:FormView>
    
        <br />
&nbsp;&nbsp;<strong>&nbsp;3) DATALIST</strong><br />
&nbsp;<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" 
            RepeatColumns="3" Height="344px" Width="948px" 
            OnItemCommand="datalist1_show">
         <ItemTemplate>
         <b>Roll</b>
             <asp:TextBox ID="txtroll" runat="server" Text='<%#Eval("roll") %>'></asp:TextBox>
             <br />
             <b>Name</b>
             <asp:TextBox ID="txtname" runat="server" Text='<%#Eval("name") %>'></asp:TextBox>
             <br />
             <b>mobile</b>
             <asp:TextBox ID="txtmobile" runat="server" Text='<%#Eval("mobile") %>'></asp:TextBox>
             <br />
             <b>City</b>
             <asp:TextBox ID="txtcity" runat="server" Text='<%#Eval("city") %>'></asp:TextBox>
             <br />
             <asp:Button ID="Button7" runat="server" Text="Submit" CommandName="datasubmit" />
             <asp:Button ID="Button6" runat="server" Text="Update" CommandName="dataupdate" />
             <asp:Button ID="Button8" runat="server" Text="Delete" CommandName="datadelete" />
             <asp:Button ID="Button9" runat="server" Text="Grid" CommandName="datagrid" />
             <hr />
         </ItemTemplate>
        </asp:DataList>
&nbsp;&nbsp;<br />
        <br />
        &nbsp;&nbsp;&nbsp; <strong>4 ) REPEATER</strong><br />
        <br />
&nbsp;&nbsp;
        <asp:Repeater ID="Repeater1" runat="server" OnItemCommand="showrep1_show">
        <ItemTemplate>
        <b>Roll</b>
            <asp:TextBox ID="txtroll" runat="server" Text='<%#Eval("roll") %>'></asp:TextBox>
            <br />
            <b>Name</b>
            <asp:TextBox ID="txtname" runat="server" Text='<%#Eval("name") %>'></asp:TextBox>
            <br />
            <b>Mobile</b>
            <asp:TextBox ID="txtmobile" runat="server" Text='<%#Eval("mobile") %>'></asp:TextBox>
            <br />
            <b>City</b>
            <asp:TextBox ID="txtcity" runat="server" Text='<%#Eval("city") %>'></asp:TextBox>
            <br />
            <asp:Button ID="Button17" runat="server" Text="Update" CommandName="repupd" />
            <asp:Button ID="Button16" runat="server" Text="delete" CommandName="repdel" />

            <hr />
        </ItemTemplate>
        </asp:Repeater>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    
        <br />
        <br />
    
        <br />
&nbsp;&nbsp;&nbsp; <strong>5 ) DetailView </strong>
           <br />
       &nbsp;<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
            Height="177px" Width="311px">
            <Fields>
                <asp:TemplateField HeaderText="roll">
                <ItemTemplate>
                    <asp:TextBox ID="txtroll" runat="server" Text='<%# Eval("roll") %>'></asp:TextBox>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="name">
                <ItemTemplate>
                    <asp:TextBox ID="txtname" runat="server" Text='<%# Eval("name") %>'></asp:TextBox>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="mobile">
                <ItemTemplate>
                    <asp:TextBox ID="txtmobile" runat="server" Text='<%# Eval("mobile") %>'></asp:TextBox>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="city">
                <ItemTemplate>
                    <asp:TextBox ID="txtcity" runat="server" Text='<%# Eval("city") %>'></asp:TextBox>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Grid">
                <ItemTemplate>
                    <asp:Button ID="Button11" runat="server" Text="Grid" />
                </ItemTemplate>
                </asp:TemplateField>
            </Fields>
        </asp:DetailsView>
    
        <br />
        <br />
&nbsp;&nbsp; <strong>6 ) LISTVIEW</strong><br />
        <br />
&nbsp;<asp:ListView ID="ListView1" runat="server" >
<ItemTemplate>
<b>roll</b>
    <asp:TextBox ID="txtroll" runat="server" Text='<%#Eval("roll") %>'></asp:TextBox>
    <br />
    <b>name</b>
    <asp:TextBox ID="txtname" runat="server" Text='<%#Eval("name") %>'></asp:TextBox>
    <br />
    <b>mobile</b>
    <asp:TextBox ID="txtmobile" runat="server" Text='<%#Eval("mobile") %>'></asp:TextBox>
    <br />
    <b>city</b>
    <asp:TextBox ID="txtcity" runat="server" Text='<%#Eval("city") %>'></asp:TextBox>
    <hr />
</ItemTemplate>
        </asp:ListView>
    
    </div>
    </form>
</body>
</html>


button Code :- Gridinall.Aspx.Cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;   // microsoft access library

public partial class ZZZAccessinall_gridimpliment_ : System.Web.UI.Page
{
    OleDbConnection cn;
    OleDbCommand cm;
    OleDbDataReader dr;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            show();
        }
    }
    protected void show()
    {
        string connection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/library.mdb";   // provider
        cn = new OleDbConnection(connection);
        cn.Open();

        string k = "select * from library";
        cm = new OleDbCommand(k, cn);
        dr = cm.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
    }
    protected void submit1_click(object sender, EventArgs e)
    {
        string connection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/library.mdb";   // provider
        cn = new OleDbConnection(connection);
        cn.Open();

        GridViewRow r1 = ((Button)sender).NamingContainer as GridViewRow;

        TextBox txtro = (TextBox)r1.FindControl("txtroll");
        TextBox txtna = (TextBox)r1.FindControl("txtname");
        TextBox txtmob = (TextBox)r1.FindControl("txtmobile");
        TextBox txtci = (TextBox)r1.FindControl("txtcity");

        string k2 = "select count(roll)+1 from library";
        cm = new OleDbCommand(k2, cn);

        txtro.Text = cm.ExecuteScalar().ToString();

        string k = "insert into library(roll,name,mobile,city)values(@roll1,@name1,@mobile1,@city1)";
        cm = new OleDbCommand(k, cn);
        cm.Parameters.AddWithValue("roll1", txtro.Text);
        cm.Parameters.AddWithValue("name1", txtna.Text);
        cm.Parameters.AddWithValue("mobile1", txtmob.Text);
        cm.Parameters.AddWithValue("city1", txtci.Text);
        cm.ExecuteNonQuery();
        Response.Write("data inserted succesfully");
    }
    protected void update1_click(object sender, EventArgs e)
    {
        string connection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/library.mdb";   // provider
        cn = new OleDbConnection(connection);
        cn.Open();

        GridViewRow r1 = ((Button)sender).NamingContainer as GridViewRow;
        TextBox txtro = (TextBox)r1.FindControl("txtroll");
        TextBox txtna = (TextBox)r1.FindControl("txtname");
        TextBox txtmob = (TextBox)r1.FindControl("txtmobile");
        TextBox txtci = (TextBox)r1.FindControl("txtcity");

        string k = "update library set name=@name1,mobile=@mobile1,city=@city1 where roll=@roll1";
        cm = new OleDbCommand(k, cn);
        cm.Parameters.AddWithValue("name1", txtna.Text);
        cm.Parameters.AddWithValue("mobile1", txtmob.Text);
        cm.Parameters.AddWithValue("city1", txtci.Text);
        cm.Parameters.AddWithValue("roll1", txtro.Text);
        cm.ExecuteNonQuery();
        Response.Write("data updated succesfully");
    }
    protected void delete1_click(object sender, EventArgs e)
    {
        string connection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/library.mdb";   // provider
        cn = new OleDbConnection(connection);
        cn.Open();

        GridViewRow r1 = ((Button)sender).NamingContainer as GridViewRow;
        TextBox txtro = (TextBox)r1.FindControl("txtroll");

        string k = "delete from library where roll=@roll1";
        cm = new OleDbCommand(k, cn);
        cm.Parameters.AddWithValue("roll1", txtro.Text);
        cm.ExecuteNonQuery();
        Response.Write("data deleted succsfully");
    }
    protected void formview1_click(object sender, EventArgs e)
    {
        string connection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/library.mdb";   // provider
        cn = new OleDbConnection(connection);
        cn.Open();

        GridViewRow r1 = ((Button)sender).NamingContainer as GridViewRow;
        TextBox txtro=(TextBox)r1.FindControl("txtroll");

        string k = "select * from library where roll=@roll1";
        cm = new OleDbCommand(k, cn);
        cm.Parameters.AddWithValue("roll1", txtro.Text);
        dr = cm.ExecuteReader();
        FormView1.DataSource = dr;
        FormView1.DataBind();
        dr.Close();
    }
    protected void datalist1_click(object sender, EventArgs e)
    {
        string connection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/library.mdb";   // provider
        cn = new OleDbConnection(connection);
        cn.Open();

        GridViewRow r1 = ((Button)sender).NamingContainer as GridViewRow;

        string k = "select * from library";
        cm = new OleDbCommand(k, cn);
        dr = cm.ExecuteReader();
        DataList1.DataSource = dr;
        DataList1.DataBind();
        dr.Close();
    }
    protected void datalist1_show(object sender, DataListCommandEventArgs e)
    {
        string connection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/library.mdb";   // provider
        cn = new OleDbConnection(connection);
        cn.Open();

        TextBox txtro = (TextBox)e.Item.FindControl("txtroll");
        TextBox txtna = (TextBox)e.Item.FindControl("txtname");
        TextBox txtmob = (TextBox)e.Item.FindControl("txtmobile");
        TextBox txtci = (TextBox)e.Item.FindControl("txtcity");

        if (e.CommandName == "dataupdate")
        {
            string k = "update library set name=@name1,mobile=@mobile1,city=@city1 where roll=@roll1";
            cm = new OleDbCommand(k, cn);
            cm.Parameters.AddWithValue("name1", txtna.Text);
            cm.Parameters.AddWithValue("mobile1", txtmob.Text);
            cm.Parameters.AddWithValue("city1", txtci.Text);
            cm.Parameters.AddWithValue("roll1", txtro.Text);
            cm.ExecuteNonQuery();
            Response.Write("data updated succesfully");
        }

        if (e.CommandName == "datasubmit")
        {
            string k2 = "select count(roll)+1 from library";
            cm = new OleDbCommand(k2, cn);

            txtro.Text = cm.ExecuteScalar().ToString();

            string k1 = "insert into library(roll,name,mobile,city)values(@roll1,@name1,@mobile1,@city1)";
            cm = new OleDbCommand(k1, cn);
            cm.Parameters.AddWithValue("roll1", txtro.Text);
            cm.Parameters.AddWithValue("name1", txtna.Text);
            cm.Parameters.AddWithValue("city1", txtci.Text);
            cm.Parameters.AddWithValue("roll1", txtro.Text);
            cm.ExecuteNonQuery();
            Response.Write("data submitted succesfully");
        }
        if(e.CommandName=="datadelete")
        {
            string k3 = "delete from library where roll=@roll1";
            cm=new OleDbCommand(k3,cn);
            cm.Parameters.AddWithValue("roll1",txtro.Text);
            cm.ExecuteNonQuery();
            Response.Write("data deleted succesfully");
        }
        if (e.CommandName == "datagrid")
        {
            string k4 = "select * from library where roll=@roll1";
            cm = new OleDbCommand(k4, cn);
            cm.Parameters.AddWithValue("roll1", txtro.Text);
            dr = cm.ExecuteReader();
            GridView1.DataSource = dr;
            GridView1.DataBind();
            dr.Close();
        }
    }
    protected void detailview_click(object sender, EventArgs e)
    {
        string connection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/library.mdb";   // provider
        cn = new OleDbConnection(connection);
        cn.Open();

        GridViewRow r1 = ((Button)sender).NamingContainer as GridViewRow;
        TextBox txtro = (TextBox)r1.FindControl("txtroll");

        string k = "select * from library where roll=@roll1";
        cm = new OleDbCommand(k, cn);
        cm.Parameters.AddWithValue("roll1", txtro.Text);
        dr = cm.ExecuteReader();
        DetailsView1.DataSource = dr;
        DetailsView1.DataBind();
        dr.Close();
    }
    protected void listview1_click(object sender, EventArgs e)
    {
        string connection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/library.mdb";   // provider
        cn = new OleDbConnection(connection);
        cn.Open();

        GridViewRow r1 = ((Button)sender).NamingContainer as GridViewRow;
        TextBox txtro = (TextBox)r1.FindControl("txtroll");

        string k = "select * from library where roll=@roll1";
        cm = new OleDbCommand(k, cn);
        cm.Parameters.AddWithValue("roll1", txtro.Text);
        dr = cm.ExecuteReader();
        ListView1.DataSource = dr;
        ListView1.DataBind();
        dr.Close();
    }
    protected void update111_click(object sender, EventArgs e)
    {
        string connection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/library.mdb";   // provider
        cn = new OleDbConnection(connection);
        cn.Open();

        GridViewRow r1 = ((Button)sender).NamingContainer as GridViewRow;
        TextBox txtro = (TextBox)r1.FindControl("txtroll");
        TextBox txtna = (TextBox)r1.FindControl("txtname");
        TextBox txtmob = (TextBox)r1.FindControl("txtmobile");
        TextBox txtci = (TextBox)r1.FindControl("txtcity");

        cm = new OleDbCommand("accesup", cn);
        cm.CommandType = CommandType.StoredProcedure;
        cm.Parameters.AddWithValue("roll1", txtro.Text);
        cm.Parameters.AddWithValue("name1", txtna.Text);
        cm.ExecuteNonQuery();
        Response.Write("data updated succesfully");
    }
    protected void ClassSubmit1_click(object sender, EventArgs e)
    {
        GridViewRow r1 = ((Button)sender).NamingContainer as GridViewRow;
        TextBox txtro = (TextBox)r1.FindControl("txtroll");
        TextBox txtna = (TextBox)r1.FindControl("txtname");
        TextBox txtmob = (TextBox)r1.FindControl("txtmobile");
        TextBox txtci = (TextBox)r1.FindControl("txtcity");

        int a;
        msaccsubmit ms1 = new msaccsubmit();
        a = int.Parse(txtro.Text);
        ms1.Submitdata(a, txtna.Text, txtmob.Text, txtci.Text);
        Response.Write("data submitted succesfully");
    }
    protected void reapeater1_click(object sender, EventArgs e)
    {
        string connection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/library.mdb";   // provider
        cn = new OleDbConnection(connection);
        cn.Open();

        GridViewRow r1 = ((Button)sender).NamingContainer as GridViewRow;
        TextBox txtro = (TextBox)r1.FindControl("txtroll");

        string k = "select * from library where roll=@roll1";
        cm = new OleDbCommand(k, cn);
        cm.Parameters.AddWithValue("roll1", txtro.Text);
        dr = cm.ExecuteReader();
        Repeater1.DataSource = dr;
        Repeater1.DataBind();
        dr.Close();
    }
    protected void showrep1_show(object sender, RepeaterCommandEventArgs e)
    {
        string connection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:/library.mdb";   // provider
        cn = new OleDbConnection(connection);
        cn.Open();

        TextBox txtR = (TextBox)e.Item.FindControl("txtroll");
        TextBox txtN = (TextBox)e.Item.FindControl("txtname");
        TextBox txtM = (TextBox)e.Item.FindControl("txtmobile");
        TextBox txtC = (TextBox)e.Item.FindControl("txtcity");

        if (e.CommandName == "repupd")
        {
            string k1 = "update library set name=@name1 where roll=@roll1";
            cm = new OleDbCommand(k1, cn);
            cm.Parameters.AddWithValue("name1", txtN.Text);
            cm.Parameters.AddWithValue("roll1", txtR.Text);
            cm.ExecuteNonQuery();
            Repeater1.DataSource = dr;
            Repeater1.DataBind();
            Response.Write("data updated succesfully");
        }

        if (e.CommandName == "repdel")
        {
            string k = "delete from library where roll=@roll1";
            cm = new OleDbCommand(k, cn);
            cm.Parameters.AddWithValue("roll1", txtR.Text);
            cm.ExecuteNonQuery();
            Repeater1.DataSource = dr;
            Repeater1.DataBind();
            Response.Write("delete data succesfully");
        }
    }
}

                                 

Comments

Popular posts from this blog

DATA CONTROL ( Gridview , Repeater , Formview , DataList , Detailsview , Listview )

Z 5 ) MVC (Model view Controller)

Z 8 ) MVC HTMLHELPER METHOD AND ACTIONLINK (how to use css ,atrributes,style in css)