Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my code.Can anyone say what is the error??
C#
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.OleDb;



namespace gasbooking
{
    public partial class WebForm1 : System.Web.UI.Page
    {
             protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {

                OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Arunkumar\Documents\Visual Studio 2012\Projects\reg.accdb");
                
                ClientScript.RegisterStartupScript(GetType(), "alert", "alert('connection opened')", true);
                 OleDbCommand cmd = new OleDbCommand("insert into userdetails values(@Distributor,@LPG_ID,@Username,@E-Mail ID,@Password,@MBL_NO,@AadharNO,@Address,@PINCODE)",con  );
                cmd.Parameters.AddWithValue("Distributor",DropDownList2.SelectedValue );
                cmd.Parameters.AddWithValue("LPG_ID",TextBox1 .Text );
                cmd.Parameters.AddWithValue("UserName",TextBox2 .Text );
                cmd.Parameters.AddWithValue("E-Mail ID",TextBox3 .Text );
                cmd.Parameters.AddWithValue("Password",TextBox8 .Text );
                cmd.Parameters.AddWithValue("MBL_NO",TextBox4 .Text );
                cmd.Parameters.AddWithValue("AadharNO",TextBox5 .Text );
                cmd.Parameters.AddWithValue("Address",TextBox6 .Text);
                cmd.Parameters.AddWithValue("PINCODE",TextBox7 .Text );
                int i =cmd.ExecuteNonQuery();

                if (i > 0)
                {
                    ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Registered successfully')", true);
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Data Not Inserted')", true);
                }
                
                Response.Redirect("login.aspx");
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
            
                  }
        protected void Button2_Click(object sender, EventArgs e)
        {
            Page.Response.Redirect(Page.Request.Url.ToString(), true);
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Response.Redirect("Login.aspx");
        }

       
    }
}
Posted
Updated 21-Mar-15 7:39am
v2
Comments
jgakenhe 21-Mar-15 13:20pm    
Check the eventlog, it will provide you the answer.

1 solution

I suspect it's the name E-Mail ID.

I'm guessing by your use of OleDb and the ACE engine that you're using Access. You need to be careful with parameters with those.

0) OleDb doesn't really use parameter names, so you can't use the parameters out of order.
1) You may need to list the column names; not all RDBMs allow you to leave it out.
 
Share this answer
 
v2
Comments
Maciej Los 21-Mar-15 16:01pm    
You're right and wrong (all in one) ;)
Email ID - right! It should be one word.
OleDb doesn't really use parameter names - wrong, because of MS Access engine can use named parameters. I mentioned it several times.
Fanlly: +5!
PIEBALDconsult 21-Mar-15 18:03pm    
Yes, you can use named parameters with Access, the ACE engine, and the OleDb ADO.net provider, with limitations; such as order. Or have they improved it in the last few years?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900