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

c#用WPF数据库问题
用c#编了一个WPF小程序,用的是access数据库,写入时出现错误,请大家帮忙解决

  private void button1_Click(object sender, RoutedEventArgs e)
  {
  string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=meTest.MDB";
  string strISQL = "INSERT INTO we( Name, Address, date) VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
  OleDbConnection myConn = new OleDbConnection(strDSN);
  myConn.Open();
  OleDbCommand myCmd = new OleDbCommand(strISQL, myConn);
  myCmd.ExecuteNonQuery();

  }

提示说:INSERT INTO 语法错误


------解决方案--------------------
Access中注意关键字,要使用[]包裹一下

string strISQL = "INSERT INTO we([Name], Address, [date]) VALUES('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";