用access数据库实现更新问题

  string Connection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + HttpContext.Current.Server.MapPath("Data/" + ConfigurationManager.ConnectionStrings["OleDbName"].ConnectionString);
        string sql1 = "update [AdminInfo] set AdminName=@AdminName where AdminID=@AdminID";
        string sql2 = "update [AdminInfo] set AdminName='bbbb',AdminPassWord='ss' where AdminID='10010'";
        using (OleDbConnection con = new OleDbConnection(Connection))
        {
            con.Open();
            OleDbTransaction trans = con.BeginTransaction();
            OleDbCommand com = new OleDbCommand(sql0, con);
            com.Transaction = trans;

            com.Parameters.AddWithValue("@AdminName", "hu");
            com.Parameters.AddWithValue("@AdminID", "10010"); ;           
            try
            {
                com.ExecuteNonQuery();

                trans.Commit();

            }
            catch (Exception ex)
            {
                trans.Rollback();
                throw new Exception(ex.ToString());

            }

        }

为什么 用sql1更新不成功,也没有什么异常出现,用sql2来做就可以,在做添加操作时都是可以成功的.请高手指点,(我用的是access数据库)

Helenr
浏览 494回答 1
1回答

慕斯709654

access要用?代替@
打开App,查看更多内容
随时随地看视频慕课网APP