 |
| 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
|
|
|
|

August 1st, 2003, 06:16 AM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 !
|
|

August 4th, 2003, 03:37 AM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Pls help.....
|
|

August 4th, 2003, 03:55 AM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 5th, 2003, 02:08 AM
|
|
Authorized User
|
|
Join Date: Jul 2003
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hai,
The problem still there. How ??
|
|

August 25th, 2003, 01:32 AM
|
|
Registered User
|
|
Join Date: Aug 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 25th, 2003, 01:33 AM
|
|
Registered User
|
|
Join Date: Aug 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
"password" is a key word. you must either change the name of the field or enclose it in brackets in your statement - [password]
|
|

August 25th, 2003, 01:35 AM
|
|
Registered User
|
|
Join Date: Aug 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
password is a key word. you must either re-name the field or enclose it in brackets within you statement - [password]
|
|
 |