Error while entering into database
Hi,
I am trying to insert a password and username into database. I am hashing the password first and then entering it into the database. When I submit the request Iget this error: -
Syntax error in INSERT INTO statement.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
Source Error:
Line 28: // you're accessing an external resource that could fail.
Line 29: objConnection.Open();
Line 30: objCommand.ExecuteNonQuery();
Line 31: objConnection.Close();
Line 32: }
Source File: D:\House or Home Site\Admin\register.aspx Line: 30
Here is my code: -
<script language="C#" runat="server">
private void addUser(object sender, System.EventArgs e)
{
string UserName = txtUserName.Text;
string Password = txtPassword.Text;
const string CONNSTR = "Provider=Microsoft.Jet.OleDb.4.0.; data source= D:\\House or Home site\\House.mdb;";//\\premfs3\\sites\\premium8\\adnanarab66\\database\ \House.mdb;";
string hashedPwd = FormsAuthentication.HashPasswordForStoringInConfig File(Password,"SHA1");
String strSQL = "INSERT INTO Users (UserName, Password) VALUES (?,?)";
OleDbConnection objConnection = new OleDbConnection(CONNSTR);
OleDbCommand objCommand = new OleDbCommand(strSQL, objConnection);
objCommand.Parameters.Add("UserName", OleDbType.VarChar, 32, "UserName");
objCommand.Parameters.Add("Password", OleDbType.VarChar, 32, "Password");
objCommand.Parameters["UserName"].Value = UserName;
objCommand.Parameters["Password"].Value = hashedPwd;
// in real life add try--catch block because
// you're accessing an external resource that could fail.
objConnection.Open();
objCommand.ExecuteNonQuery();
objConnection.Close();
}
</script>
Any ideas??
Adz - The World is not enough
__________________
Adz - Learning The J2EE Ways.
|