using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Web.SessionState;
/// <summary>
///Method 的摘要说明
/// </summary>
public class Method
{
public Method()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public static readonly string cnnstring=ConfigurationManager.ConnectionStrings["con"].ConnectionString;
/// <summary>
/// olecmd为要执行的命令
/// commandtype是命令的类型
/// para是参数集合
/// 返回类型为DataTable
/// </summary>
/// <param name="sqlcmd"></param>
/// <param name="commandtype"></param>
/// <param name="para"></param>
/// <returns></returns>
public static DataTable Returm(string olecmd,CommandType commandtype,params OleDbParameter[] para)
{
using (OleDbConnection con = new OleDbConnection(cnnstring))
{
using (OleDbCommand cmd = new OleDbCommand(olecmd,con))
{
cmd.Parameters.AddRange(para);
using (OleDbDataAdapter oda = new OleDbDataAdapter(cmd))
{
DataTable dt = new DataTable();
oda.Fill(dt);
return dt;
}
}
}
}
/// <summary>
/// olecmd要执行的命令
/// commandtype命令类型
/// parar为命令的参数
/// 返回类型为void
/// 执行的操作为,增删除,修改,
/// </summary>
/// <param name="sqlcmd"></param>
/// <param name="commandtype"></param>
/// <param name="parar"></param>
public static void OleExecute(string olecmd,CommandType commandtype,params OleDbParameter[] parar)
{
using (OleDbConnection con = new OleDbConnection(cnnstring))
{
using (OleDbCommand cmd = new OleDbCommand(olecmd,con))
{
cmd.Parameters.AddRange(parar);
con.Open();
cmd.ExecuteNonQuery();
}
}
}
/// <summary>
/// olecmd要执行的命令
/// commandtype命令类型
/// parar为命令的参数
/// 返回类型为string
/// 判断记录是否存在
/// 以及返回符合条件的总记录数
/// 适用于用户登录
/// </summary>
/// <param name="olecmd"></param>
/// <param name="commantye"></param>
/// <param name="para"></param>
/// <returns></returns>
public static string OleYnRecord(string olecmd,CommandType commantye, params OleDbParameter[] para)
{
using (OleDbConnection con = new OleDbConnection(cnnstring))
{
using (OleDbCommand cmd = new OleDbCommand(olecmd,con))
{
DataSet ds = new DataSet();
cmd.Parameters.AddRange(para);
using (OleDbDataAdapter ada = new OleDbDataAdapter(cmd))
{
ada.Fill(ds);
if (ds.Tables[0].Rows.Count == 0)
{
return "no"; //无找到记录返回no
}
else if (ds.Tables[0].Rows.Count == 1)
{
return "yes"; //存在一条记录返回yes
}
else
{
return ds.Tables[0].Rows.Count.ToString(); //返回总记录数
}
}
}
}
}
}