SqlHelper类

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

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}}

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功