How to insert simple record in a Access data base 2007

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vkas
    New Member
    • Feb 2009
    • 78

    #1

    How to insert simple record in a Access data base 2007

    I have a default .aspx form

    i HAVE 3 TEXT BOX
    1 DROPDOWN LIST IN MY DEFAULT PAGE.
    a access data base file at locaion C:\asp.netdb\fe edback.accdb

    I want to insert the values into the access database from this page

    my default.aspx code is
    Code:
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!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>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            Feed Back form!<br />
            <table style="width: 271px; height: 140px;">
                <tr>
                    <td>
                        <asp:Label ID="Label2" runat="server" Text="Name"></asp:Label></td>
                    <td>
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label3" runat="server" Text="Email"></asp:Label></td>
                    <td>
                        <asp:TextBox ID="TextBox3" runat="server" style="margin-bottom: 0px"></asp:TextBox></td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label1" runat="server" Text="Feed back for"></asp:Label></td>
                    <td>
                        <asp:DropDownList ID="DropDownList1" runat="server">
                            <asp:ListItem>IT department</asp:ListItem>
                            <asp:ListItem>Degree attestion</asp:ListItem>
                            <asp:ListItem>Finance department</asp:ListItem>
                        </asp:DropDownList></td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="Label4" runat="server" Text="Feedback detail"></asp:Label></td>
                    <td>
                        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td align="center" colspan="2" style="height: 26px">
                        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />&nbsp; </td>
                </tr>
            </table>  </form>
    </body>
    </html>
    my default.aspx.cs page code is

    Code:
    protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
    
                string empname, usremail, slctdep, feebdiscrp, constr;
                OleDbConnection con;
                OleDbCommand cmd;
                OleDbDataAdapter adopter;
                constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/asp.netdb/feedback.accdb; Persist Security Info=False";
                empname = TextBox1.Text;
                usremail = TextBox3.Text;
                slctdep = DropDownList1.SelectedValue;
                feebdiscrp = TextBox2.Text;
                con = new OleDbConnection(constr);
                string dbcommand = "INSERT into feedback (Empname, UserEmail,SelectDepartment, Feedbackdiscription) " + " VALUES ('Majeed','s@d.com','IT department','abc discription')";
                con.Open();
                //cmd = new OleDbCommand(dbcommand, con);
                adopter = new OleDbDataAdapter(dbcommand, con);
                //            cmd.ExecuteNonQuery();
            }
            catch (Exception es)
            {
                Label5.Text = es.Message.ToString();
            }
    
           Label5.Text = "Record Successfully added";
         
      
        }
    when i insert the values and clicking the button, the button event is envoked showing no error but the record is not inserted in database

    can any have some idea?
Working...