日期:2014-05-17  浏览次数:21297 次

[C#]无效的 SQL语句;期待 'DELETE'、'INSERT'、'PROCEDURE'、'SELECT'、或 'UPDATE'。
本帖最后由 f59135 于 2013-06-09 16:36:00 编辑
                    Random r = new Random();
                    int ID = r.Next();//设置初始帐号
                    int balance = 0;
                    string str1 = textBox1.Text;
                    string str2 = textBox2.Text;
string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;data source=D:\\Bank.mdb";
                        OleDbConnection con = new OleDbConnection(ConStr); 
                        con.Open();
                        if (con.State == ConnectionState.Open)
                            MessageBox.Show("连接成功!", "数据库状态信息");
                        else
                            MessageBox.Show("ERROR!", "数据库状态信息");

                        string sql = "insert??Bank(账号,姓名,密码,余额) VALUES('"+ID+"','"+str1+"','"+str2+"','"+ balance+"')";
                    
                        OleDbCommand cmd = new OleDbCommand(sql, con); 
                        cmd.ExecuteNonQuery();
                        cmd.Dispose();
                        con.Close();