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

下列webservice代码为何不能更新数据库
下列webservice代码为何不能更新数据库?我用的是winform端调用的websevice,SQL的值为"insert into user_log(类型,用户名) values ('" + lx + "','" + yhm + "') "; 
C# code

[WebMethod(Description = "接收日志记录")]
    
    public DataSet GetDataset(string SQL)
    {
        #region 将UserLog复制并改为带当前日期的MDB
        string NowDate = DateTime.Now.ToString("yyyy-MM-dd");
        string[] jie = NowDate.Split('-');
        string sourceFile = AppDomain.CurrentDomain.BaseDirectory + "\\App_Data\\UserLog.mdb";
        string targetFile = AppDomain.CurrentDomain.BaseDirectory + "\\App_Data\\UserLog" + jie[0] + jie[1] + jie[2] + ".mdb";
        if (File.Exists(targetFile) == false)
        {
            File.Copy(sourceFile, targetFile);
        }
        #endregion
        Connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+targetFile+";Persist Security Info=False";
        OleDbConnection MyConn = new OleDbConnection(Connstr);
        try
        {
            MyConn.Open();
            OleDbDataAdapter MyCommand = new OleDbDataAdapter(SQL, MyConn);
            OleDbCommand Mycmd = new OleDbCommand(SQL, MyConn);
            Mycmd.ExecuteNonQuery();            
            DataSet ds = new DataSet();
            MyCommand.Fill(ds);
            MyConn.Close();
            return ds;
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }



------解决方案--------------------
你可以看下SQLDATAADAPTER更新部分:
http://msdn.microsoft.com/zh-cn/library/at8a576f.aspx
------解决方案--------------------
C# code

 MyConn.Open();
  
            OleDbCommand Mycmd = new OleDbCommand(SQL, MyConn);
            Mycmd.ExecuteNonQuery();