日期:2014-05-18  浏览次数:20445 次

access,INSERT INTO 语句的语法错误
Exception Details: System.Data.OleDb.OleDbException: INSERT INTO 语句的语法错误。
C# code

protected void Button1_Click(object sender, EventArgs e)
    {
        hostname = Request.QueryString["id"].ToString();//全局变量,此处无错。
        string str = System.Web.HttpContext.Current.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings["dbPath"]);
        OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + str);
        String strSQL = "SELECT * FROM [reviews] WHERE Host='"+hostname+"'";
        OleDbDataAdapter objCmd = new OleDbDataAdapter(strSQL, myConn);
        DataSet ds = new DataSet();
        objCmd.Fill(ds, "reviews");
        if (ds.Tables["reviews"].Rows.Count == 0)
        {
            string myInsertQuery = "insert into reviews (t-link,t-content) values ('" + TextBox2.Text + "','" + TextBox3.Text + "')";  
            OleDbCommand myOleDbCommand = new OleDbCommand(myInsertQuery);
            myOleDbCommand.Connection = myConn;
            myConn.Open();
            myOleDbCommand.ExecuteNonQuery();//显示此行出错。
            myConn.Close();
        }
        else
        {
           ....
        }
    }



------解决方案--------------------
把你拼接完的SQL语句打出来看看
------解决方案--------------------
t-link,t-content不是合法的字段名, 不能有 '-'

------解决方案--------------------
改为
insert into reviews ([t-link],[t-content]) 
试一下