using System; using System.Data; using System.Data.SqlClient; using System.Configuration; namespace Db { public class Base { public Base() { } protected static SqlConnection conn =new SqlConnection(ConfigurationSettings.AppSettings["dsn"]); protected static SqlCommand cmd = new SqlCommand(strSp,conn); protected static SqlDataAdapter da = new SqlDataAdapter(); protected static DataSet ds = new DataSet(); protected static DataView dv = new DataView(); protected static SqlDataReader dr; protected static SqlParameter[] prams; protected static string strSp; protected static SqlDataReader drSelectAll(string strSp) { cmd.CommandType = CommandType.StoredProcedure; conn.Open(); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); return dr; }//返回一个SqlDataReader protected static DataSet dsSelectAll(string strSp) { da.SelectCommand = new SqlCommand(strSp,conn); da.SelectCommand.CommandType = CommandType.StoredProcedure; da.Fill(ds); conn.Open(); try { da.SelectCommand.ExecuteNonQuery(); return ds; } catch(Exception ex) { throw new Exception(ex.Message); } finally { conn.Dispose(); conn.Close(); } }//返回一个SqlDataSet protected static DataView dvSelectAll(string strSp) { cmd.CommandType = CommandType.StoredProcedure; da.SelectCommand = new SqlCommand(strSp,conn); da.Fill(ds);
conn.Open(); try { da.SelectCommand.ExecuteNonQuery(); dv = ds.Tables[0].DefaultView; return dv; } catch(Exception ex) { throw new Exception(ex.Message); } finally { conn.Dispose(); conn.Close(); } }//返回一个DataView protected static string strCmd(string strSp,SqlParameter[] prams,SqlDataReader dr) { CreateCmd(strSp,prams,dr); conn.Open(); try { cmd.ExecuteNonQuery(); return "1"; } catch(Exception ex) { throw new Exception(ex.Message); } finally { conn.Dispose(); conn.Close(); } }//返回一个数据库操作 protected static SqlCommand CreateCmd(string strSp, SqlParameter[] prams,SqlDataReader dr) { cmd.CommandType = CommandType.StoredProcedure; if (prams != null) { foreach (SqlParameter parameter in prams) cmd.Parameters.Add(parameter); } cmd.Parameters.Add( new SqlParameter("ReturnValue", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, 0, 0, string.Empty, DataRowVersion.Default, null)); return cmd; }//返回带参数的命令 protected static bool ExecuteSQLs() { cmd.CommandType = CommandType.StoredProcedure; conn.Open(); try { int i = (int)cmd.ExecuteScalar(); if(i>0) { return true; } else { return false; } } catch(Exception ex) { throw new Exception(ex.Message); } finally { conn.Dispose(); conn.Close(); } }//返回第一行的数据操作 } } [搜索优化]闵涛——如何让百度重新收录你的网站,网站被K怎么… [电脑应用]教你如何远程管理MSSQL数据库 [Web开发]教你如何在PHP开启gzip页面压缩实例介绍 [办公软件]在Powerpoint中如何插入Flash动画 [办公软件]如何在Powerpoint 中(实现)输入上标、下标 [办公软件]如何实现Office工具栏、菜单以及菜单命令重命名 [办公软件]如何在PowerPoint同一张幻灯片中显示大量文字 [办公软件]如何在Office文档(大)括号内输入多行文字 [办公软件]如何在office(PowerPoint,Word,Excel)中制作带圈的… [办公软件]如何删除PowerPoint幻灯片中的页脚信息
|