sqlherpel
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
public class SQLherpel
{
//连接字符
private static string strConn = ConfigurationManager.ConnectionStrings[""].ConnectionString;
//查询
public static DataTable Query(string sql)
{
SqlDataAdapter adapter = new SqlDataAdapter(sql, strConn);
DataTable table = new DataTable();
adapter.Fill(table);
return table;
}
//非查询
public static int NonQuery(string sql)
{
int num = 0;
SqlConnection sqlConnection = new SqlConnection(strConn);
SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
try
{
sqlConnection.Open();
num = sqlCommand.ExecuteNonQuery();
}
finally
{
if (sqlConnection.State == ConnectionState.Open)
sqlConnection.Close();
}
return num;
}
}
}
<configuration>
<connectionStrings>
<add name="sql" connectionString="****" providerName=""/>
</connectionStrings>
</configuration>