1

Code:

public partial class deneme1 : System.Web.UI.Page
{
OleDbConnection ConnectionString;
OleDbCommand cmdText;
protected void Page_Load(object sender, EventArgs e)
{
    ConnectionString = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ Server.MapPath("~/App_Data\\Database.mdb"));
}
protected void btnEkle_Click(object sender, EventArgs e)
{
    cmdText = new OleDbCommand("INSERT INTO Users(UserName, Password) values ('"+txtKAdi.Text+"','"+txtSifre.Text+"')", ConnectionString);

    if (ConnectionString.State == ConnectionState.Closed)
    {
        ConnectionString.Open();
    }

    cmdText.ExecuteNonQuery();
} 

When I attempt to run above code,I got the following the error.

  System.Data.OleDb.OleDbException was unhandled by user code
  Message="Syntax error in INSERT INTO statement."
  Source="Microsoft JET Database Engine"
  ErrorCode=-2147217900
  StackTrace:
   konum: System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
   konum: System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
   konum: System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
   konum: System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
   konum: System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
   konum: System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
   konum: deneme1.btnEkle_Click(Object sender, EventArgs e) c:\Users\Pc\Desktop\MasterWeb\deneme1.aspx.cs içinde: satır 32
   konum: System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   konum: System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   konum: System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   konum: System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   konum: System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   konum: System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 

1 Answer 1

2

In Access Password is reserved word so you have to quote it, ie

INSERT INTO Users(UserName, [Password]) values (...

Note the square brackets around "password".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.