日期:2014-05-17 浏览次数:20845 次
private WebLog log=null; [WebMethod] Public DataSet ds() { log=new WebLog(); log.ServiceName="WebService"; log.StartTime=DateTime.Parse(System.DateTime.Now.ToString()); //连接数据库,最后返回ds log.EndTime=DateTime.Parse(System.DateTime.Now.ToString()); WebWriteLog.Log(log); return ds; } [WebMethod] Public String str() { log=new WebLog(); log.ServiceName="WebService"; log.StartTime=DateTime.Parse(System.DateTime.Now.ToString()); //连接数据库,最后返回String log.EndTime=DateTime.Parse(System.DateTime.Now.ToString()); LogWrite.LogWriteMethod(log); return str; } //实体类: //BLL写日志 public class LogWrite { public static int LogWriteMethod(Log log) { string sel="Insert into tb values (@StartTime,@ServiceName,@EndTime);"; try { SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@StartTime", log.StartTime), new SqlParameter("@ServiceName", log.ServiceName), new SqlParameter("@EndTime", log.EndTime) }; int rows = DbHelper.ExecuteNonQuery(sel, paras); return rows; } catch { return 0; } } } DAL: public static int ExecuteNonQuery(string sql, SqlParameter[] paras) { try { using (SqlConnection conn= new SqlConnection()) { conn.Open(); SqlCommand cmd = new SqlCommand(sql, con) cmd.Parameters.AddRange(paras); return cmd.ExecuteNonQuery(); } } catch (Exception E) { throw E; } }