37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Data.SqlClient;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace Models
|
|||
|
|
{
|
|||
|
|
public class DBHelper
|
|||
|
|
{
|
|||
|
|
private readonly static string config = "Data Source=boonlive-rcu.com;Initial Catalog=CRICS;Persist Security Info=True;User ID=blw;Password=blw@#$";
|
|||
|
|
public static int ExecuteNonQuery(string sql, Action<object, SqlInfoMessageEventArgs> OnReceivingInfoMessage = null, params SqlParameter[] par)
|
|||
|
|
{
|
|||
|
|
using (SqlConnection con = new SqlConnection(config))
|
|||
|
|
{
|
|||
|
|
using (SqlCommand com = new SqlCommand(sql, con))
|
|||
|
|
{
|
|||
|
|
if (par != null && par.Length > 0)
|
|||
|
|
{
|
|||
|
|
com.Parameters.AddRange(par);
|
|||
|
|
}
|
|||
|
|
if (con.State != ConnectionState.Open)
|
|||
|
|
{
|
|||
|
|
con.Open();
|
|||
|
|
}
|
|||
|
|
if (OnReceivingInfoMessage != null) {
|
|||
|
|
con.InfoMessage += new SqlInfoMessageEventHandler(OnReceivingInfoMessage);
|
|||
|
|
}
|
|||
|
|
return com.ExecuteNonQuery();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|