public class SqlHelper conn.Open(); return rowNum; for (int i = 0; i < commandParameters.Length; i++) conn.Open(); return rowNum; ExecuteScalar的两个重载#region ExecuteScalar的两个重载 conn.Open(); return firstObj; public static object ExecuteScalar(string connStr, CommandType commandType, string commStr, params SqlParameter[] commandParameters) for (int i = 0; i < commandParameters.Length; i++) conn.Open(); return firstObj; ExecuteReader的两个重载#region ExecuteReader的两个重载 conn.Open(); return reader; public static SqlDataReader ExecuteReader(string connStr, CommandType commandType, string commStr, params SqlParameter[] commandParameters) for (int i = 0; i < commandParameters.Length; i++) conn.Open(); return reader; SqlDataSetAdapter的两个重载#region SqlDataSetAdapter的两个重载 for (int i = 0; i < commandParameters.Length; i++) sda.Fill(ds); public static DataSet SqlDataSetAdapter(string connStr, CommandType commandType, string commStr) sda.Fill(ds); }
…{
ExecuteNonQuery的两个重载#region ExecuteNonQuery的两个重载
public static int ExecuteNonQuery(string connStr, CommandType commandType, string commStr)
…{
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand(commStr, conn);
comm.CommandType = commandType;
int rowNum = comm.ExecuteNonQuery();
comm.Dispose();
conn.Close();
}
public static int ExecuteNonQuery(string connStr, CommandType commandType, string commStr, params SqlParameter[] commandParameters)
…{
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand(commStr, conn);
comm.CommandType = commandType;
comm.Parameters.Add(commandParameters[i]);
int rowNum = comm.ExecuteNonQuery();
comm.Dispose();
conn.Close();
}
#endregion
public static object ExecuteScalar(string connStr, CommandType commandType, string commStr)
…{
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand(commStr, conn);
comm.CommandType = commandType;
object firstObj = comm.ExecuteScalar();
comm.Dispose();
conn.Close();
}
…{
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand(commStr, conn);
comm.CommandType = commandType;
comm.Parameters.Add(commandParameters[i]);
object firstObj = comm.ExecuteScalar();
comm.Dispose();
conn.Close();
}
#endregion
public static SqlDataReader ExecuteReader(string connStr, CommandType commandType, string commStr)
…{
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand(commStr, conn);
comm.CommandType = commandType;
SqlDataReader reader = comm.ExecuteReader(CommandBehavior.CloseConnection);
}
…{
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand(commStr, conn);
comm.CommandType = commandType;
comm.Parameters.Add(commandParameters[i]);
SqlDataReader reader = comm.ExecuteReader(CommandBehavior.CloseConnection);
}
#endregion
public static DataSet SqlDataSetAdapter(string connStr, CommandType commandType, string commStr, params SqlParameter[] commandParameters)
…{
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand(commStr, conn);
comm.CommandType = commandType;
comm.Parameters.Add(commandParameters[i]);
SqlDataAdapter sda = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
return ds;
}
…{
SqlConnection conn = new SqlConnection(connStr);
SqlCommand comm = new SqlCommand(commStr, conn);
comm.CommandType = commandType;
SqlDataAdapter sda = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
return ds;
}
#endregion
简写的通用数据层代码_asp.net技巧
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 简写的通用数据层代码_asp.net技巧
相关推荐
-      对.net framework 反射的反思_asp.net技巧
-      .net3.5和vs2008中的asp.net ajax_asp.net技巧
-      使用asp.net ajax框架扩展html map控件_asp.net技巧
-      asp.net应用程序资源访问安全模型_asp.net技巧
-      photoshop初学者轻松绘制螺旋漩涡特效_photoshop教程
-      photoshop通道结合图层模式抠狗尾巴草_photoshop教程
-      web.config详解+asp.net优化_asp.net技巧
-      asp.net中多彩下拉框的实现_asp.net技巧