usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Configuration;namespaceDAL{publicclassSqlHelper{///summary///Á¬½Ó×Ö·û´®////summaryreadonlystringconStr=ConfigurationManager.ConnectionStrings[constr].ConnectionString;#regionÔöɾ¸Ä·½·¨///summary///Ôöɾ¸Ä·½·¨////summary///paramname=sqlsqlÓï¾ä/param///paramname=cysqlÓï¾äÀàÐÍ/param///paramname=sq²ÎÊý¸³Öµ/param///returns/returnspublicintexecuteNonQuery(stringsql,CommandTypecy,paramsSqlParameter[]sq){using(SqlConnectioncon=newSqlConnection(conStr)){SqlCommandcmd=con.CreateCommand();cmd.CommandText=sql;cmd.CommandType=cy;con.Open();if(sq.Count()!=0){cmd.Parameters.AddRange(sq);}cmd.CommandType=cy;returncmd.ExecuteNonQuery();}}#endregion#region²éѯ·µ»ØÊ×ÐÐÊ×ÁÐ///summary///²éѯ·µ»ØÊ×ÐÐÊ×ÁÐ////summary///paramname=sqlsqlÓï¾ä/param///paramname=cysqlÓï¾äÀàÐÍ/param///paramname=sq²ÎÊý¸³Öµ/param///returns/returnspublicintexecuteScalar(stringsql,CommandTypecy,paramsSqlParameter[]sq){using(SqlConnectioncon=newSqlConnection(conStr)){SqlCommandcmd=con.CreateCommand();cmd.CommandText=sql;cmd.CommandType=cy;con.Open();if(sq.Count()!=0){cmd.Parameters.AddRange(sq);}cmd.CommandType=cy;return(int)cmd.ExecuteScalar();}}#endregion#region²éѯ·½·¨///summary///²éѯµÄ·½·¨·µ»ØSqlDataReader////summary///paramname=sqlsqlÓï¾ä/param///paramname=cysqlÓï¾äÀàÐÍ/param///paramname=sq²ÎÊý¸³Öµ/param///returns/returnspublicSqlDataReaderexecuteRead(stringsql,CommandTypecy,paramsSqlParameter[]sq){SqlConnectioncon=newSqlConnection(conStr);SqlCommandcmd=con.CreateCommand();cmd.CommandText=sql;cmd.CommandType=cy;con.Open();if(sq.Count()!=0){cmd.Parameters.AddRange(sq);}cmd.CommandType=cy;returncmd.ExecuteReader(CommandBehavior.CloseConnection);}#endregion#region²éѯ·µ»ØDataTable///summary///²éѯµÄ·½·¨·µ»ØSqlDataReader////summary///paramname=sqlsqlÓï¾ä/param///paramname=cysqlÓï¾äÀàÐÍ/param///paramname=sq²ÎÊý¸³Öµ/param///returns/returnspublicDataTableallDataTble(stringsql,CommandTypecy,paramsSqlParameter[]sq){DataTabledt=newDataTable();SqlConnectioncon=newSqlConnection(conStr);SqlCommandcmd=con.CreateCommand();cmd.CommandText=sql;if(sq.Count()!=0){cmd.Parameters.AddRange(sq);}cmd.CommandType=cy;SqlDataAdapterap=newSqlDataAdapter(cmd);ap.Fill(dt);returndt;}#endregion}}