public class SqlHelper
{
private static readonly connstring = Configurationmanager.ConnectionString["connStr"].ConnectionString;
public static DataTable GetTable(string sql, CommandType type,params SqlParameter[] pars)
{
using(SqlConnection conn = new SqlConnection(connstring))
{
using(SqlDataAdapter adapter = new SqlDataAdapter(sql,conn))
{
adapter.SelectCommand.CommandType = type;
if(pars != null)
{
adapter.SelectCommand.Parameters.AddRange(pars);
}
DataTable table = new DataTable();
adapter.fill(table);
return table;
}
}
}
public static int ExecuteNoquery(string sql,CommentType type params SqlParamenter[] parrs)
{
using(SqlConnection conn = new SqlConnection(connstring))
{
using(SqlCommand cmd = new SqlCommand(sql,conn))
{
cmd.CommandType = type;
if(pars!= null)
{
cmd.Parameters.AddRange(pars);
}
conn.open();
return cmd.ExecuteNoQuery();
}
}
}
}
{
private static readonly connstring = Configurationmanager.ConnectionString["connStr"].ConnectionString;
public static DataTable GetTable(string sql, CommandType type,params SqlParameter[] pars)
{
using(SqlConnection conn = new SqlConnection(connstring))
{
using(SqlDataAdapter adapter = new SqlDataAdapter(sql,conn))
{
adapter.SelectCommand.CommandType = type;
if(pars != null)
{
adapter.SelectCommand.Parameters.AddRange(pars);
}
DataTable table = new DataTable();
adapter.fill(table);
return table;
}
}
}
public static int ExecuteNoquery(string sql,CommentType type params SqlParamenter[] parrs)
{
using(SqlConnection conn = new SqlConnection(connstring))
{
using(SqlCommand cmd = new SqlCommand(sql,conn))
{
cmd.CommandType = type;
if(pars!= null)
{
cmd.Parameters.AddRange(pars);
}
conn.open();
return cmd.ExecuteNoQuery();
}
}
}
}