当前位置: 代码迷 >> ASP.NET >> access,INSERT INTO 语句的语法异常
  详细解决方案

access,INSERT INTO 语句的语法异常

热度:1818   发布时间:2013-02-25 00:00:00.0
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]) 
试一下
  相关解决方案