Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 1st, 2003, 06:16 AM
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP.NET using C# INSERT syntex error !!

Hi,

Code:


            if (Page.IsValid)
            {
                // Save new user to the database
                string sql = "";

                string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
                strConnection += @"Data Source=d:\db1.mdb";

                sql += "INSERT INTO User(UserID, Login, Password, FName, LName,PhoneNumber, Email, IsAdministrator, Address, CellNumber, DOB)" +
                        " VALUES('" + Guid.NewGuid().ToString() +
                            "','" + txtLogin.Text +
                            "','" + txtPwd.Text +
                            "','" + txtFName.Text +
                            "','" + txtLName.Text +
                            "','" + txtPhone.Text +
                            "','" + txtEmail.Text +
                            "','0',";

                // Add the optional values or Null
                if (txtAddress.Text != string.Empty)
                    sql += "'" + txtAddress.Text + "',";
                else
                    sql += "Null,";

                if (txtMobile.Text != string.Empty)
                    sql += "'" + txtMobile.Text + "',";
                else
                    sql += "Null,";

                if (txtBirth.Text != string.Empty)
                    sql += "'" + txtBirth.Text + "')";
                else
                    sql += "Null)";


                this.lblError.Text = sql;

                // Connect and execute the query
                OleDbConnection objConnection = new OleDbConnection(strConnection);
                OleDbCommand objCommand = new OleDbCommand(sql, objConnection);

                bool doredirect = true;

                try
                {
                    objConnection.Open();
                    objCommand.ExecuteNonQuery();
                }
                catch(Exception e)
                {
                    doredirect = false;
                    this.lblMessage.Visible = true;
                    this.lblMessage.Text = e.Message.ToString();//"Insert couldn't be performed. User name may be already taken.";
                }
                finally
                {
                    objConnection.Close();
                }

                if (doredirect)
                    Response.Redirect("Login.aspx");
            }
            else
                lblMessage.Text = "Fix the following errors and retry:";
}


When I ran this code, I got the following sql statement

INSERT INTO User(UserID, Login, Password, FName, LName,PhoneNumber, Email, IsAdministrator, Address, CellNumber, DOB) VALUES('ee6e6f6d-4d92-4915-80c2-fb44d7003d7e','8','9','8','8','906-482-0143','[email protected]','0','68','66','12-08-55')


and error:

Syntax error in INSERT INTO statement.


I cut and paste the sql statement the Access 2K and execute the query and it successfully inserted into the table.
How come C# unble to insert and keep complaining that Syntax error. I don't really see any syntax error there.
Pls help !
 
Old August 4th, 2003, 03:37 AM
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Pls help.....
 
Old August 4th, 2003, 03:55 AM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hai,

   Ur coding is correct and it will work,but check weather ur database access file is having read permission or write permission, if it is in read mode just change it to writable mode then it will work fine,nothing u have to change and that access file is in anyfolder check the permisson for it also





 
Old August 5th, 2003, 02:08 AM
Authorized User
 
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hai,

  The problem still there. How ??
 
Old August 25th, 2003, 01:32 AM
Registered User
 
Join Date: Aug 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

password is a key word. you need to either change the name of the field, or enclose it in brackets [password]. login might be also

 
Old August 25th, 2003, 01:33 AM
Registered User
 
Join Date: Aug 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

"password" is a key word. you must either change the name of the field or enclose it in brackets in your statement - [password]

 
Old August 25th, 2003, 01:35 AM
Registered User
 
Join Date: Aug 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

password is a key word. you must either re-name the field or enclose it in brackets within you statement - [password]






Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert data in SQL ASP .NET 2.0. alexsaiz82 ASP.NET 2.0 Basics 0 January 3rd, 2006 03:28 PM
Problem in insert new data in Asp.Net. Rahul Gupta ASP.NET 1.0 and 1.1 Basics 1 December 16th, 2005 10:23 AM
error '80040e14' Syntex error in From clause alisonchase Access ASP 5 January 2nd, 2005 10:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.