I have a problem while attempting to insert values into a table in my asp.net web application. I keep getting the error System.Data.OleDb.OleDbException (0x80040E14): Syntax error in INSERT INTO statement. at... I'm not sure why, I'm hoping its just a typo. But here is my Datalayer class code:
public void RegisterUser(string username, string city, string state, string favLang, string leastFavLang, string date, string password)
{
dbConnection.Open();
string sqlStmt = "INSERT INTO tblUserInfo (Username, City, State, FavoriteLanguage, LeastFavoriteLanguage, lastComplete, Password)";
// sqlStmt += "VALUES (" + username + ", " + city + ", " + state + ", " + favLang + ", " + leastFavLang + ", " + date + ", " + password + ")";
sqlStmt += " VALUES (@username, @city, @state, @favLang, @leastFavLang, @compDate, @password)";
OleDbCommand dbCommand = new OleDbCommand(sqlStmt, dbConnection);
OleDbParameter param = new OleDbParameter("@username", username);
dbCommand.Parameters.Add(param);
dbCommand.Parameters.Add(new OleDbParameter("@city",city));
dbCommand.Parameters.Add(new OleDbParameter("@state",state));
dbCommand.Parameters.Add(new OleDbParameter("@favLang",favLang));
dbCommand.Parameters.Add(new OleDbParameter("@leastFavLang",leastFavLang));
dbCommand.Parameters.Add(new OleDbParameter("@compDate",date));
dbCommand.Parameters.Add(new OleDbParameter("@password",password));
dbCommand.ExecuteNonQuery();
dbConnection.Close();
}
And here is the c# behind the page:
protected void AddToDB_Click(object sender, EventArgs e)
{
bool userAddError = false;
string tempPath = Server.MapPath("Programaholics.accdb");
clsDataLayer myDataLayer = new clsDataLayer(tempPath);
try
{
myDataLayer.RegisterUser(lblUsername.Text, lblCity.Text, lblState.Text, lblFavLang.Text, lblLeastFavLang.Text, lblDate.Text,lblpass.Text);
}
catch (Exception error)
{
userAddError = true;
string message = "Error.";
Master.MasterLabel.Text = message + "" + error;
}
if (!userAddError)
{
Master.MasterLabel.Text = "User added";
}
}
yes, it is a project for school I've already written the code I just need help troubleshooting why it wont work.
User contributions licensed under CC BY-SA 3.0