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 个解决方案
#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".
请注意“密码”周围的方括号。
#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".
请注意“密码”周围的方括号。