本文介绍了尝试使用Microsoft访问.mdb插入数据时出现C#SQL语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 static OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings [dbProject]。ConnectionString); 执行查询时出现SQL语法错误。 public static void InsertLogins(User u) { conn.Open(); OleDbCommand cmd = new OleDbCommand( Insert到tblLogin(用户名,密码,CharPreset)值(' + u.Username + ',' + u.Password + ',' + u.CharPreset + '),conn); cmd.ExecuteNonQuery(); conn.Close(); } 我可以从数据库中读取使用此查询 OleDbCommand cmd = new OleDbCommand( 选择*来自tblLogin,conn); 我尝试过: 我能想到的一切。它在使用SQL服务器时有效,但我希望它能与Microsoft Access一起使用解决方案 static OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["dbProject"].ConnectionString); Im getting SQL syntax error when executing the query.public static void InsertLogins(User u) { conn.Open(); OleDbCommand cmd = new OleDbCommand("Insert into tblLogin(Username,Password,CharPreset) values ('" + u.Username + "','" + u.Password + "','" + u.CharPreset + "')", conn); cmd.ExecuteNonQuery(); conn.Close(); } I can read from the database using this query OleDbCommand cmd = new OleDbCommand("Select * From tblLogin", conn);What I have tried:Everything I could think of. It works when using SQL server but I want it to work with Microsoft Access 解决方案 这篇关于尝试使用Microsoft访问.mdb插入数据时出现C#SQL语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-22 07:43