sqlhelper的编写
static string str = "server=ETPWQO7ANIFO8OJ\\SQLEXPRESS;database=test-1;uid=ss;pwd=123456";
我们提供的服务有:成都网站建设、做网站、微信公众号开发、网站优化、网站认证、石鼓ssl等。为1000多家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的石鼓网站制作公司
public static List
{
using (SqlConnection conn = new SqlConnection(str))
{
SqlDataAdapter da = new SqlDataAdapter(strcmd, conn);
da.SelectCommand.Parameters.AddRange(paras);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
List
foreach (DataRow row in dt.Rows)
{
Type t = typeof(T2);
T2 model = (T2)Activator.CreateInstance(t);
PropertyInfo[] proper = t.GetProperties();
foreach (PropertyInfo p in proper)
{
string colName = p.Name;
object colValue = row[colName];
p.SetValue(model, colValue, null);
}
list.Add(model);
}
return list;
}
}
return null;
}
#endregion
#region MyRegion
public static DataTable ExecuteDataTable(string sql, params SqlParameter[] parameters)
{
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(sql, str);
adapter.SelectCommand.Parameters.AddRange(parameters);
try
{
adapter.Fill(ds);
return ds.Tables[0];
}
catch { return null; }
}
#endregion
#region MyRegion
public static int ExecuteNonQuery(string sql, params SqlParameter[] parameters)
{
using (SqlConnection conn = new SqlConnection(str))
{
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.AddRange(parameters);
conn.Open();
return cmd.ExecuteNonQuery();
}
}
}
#endregion
#region MyRegion
public static object ExecuteScalar(string sql, params SqlParameter[] parameters)
{
using (SqlConnection conn = new SqlConnection(str))
{
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
cmd.Parameters.AddRange(parameters);
conn.Open();
return cmd.ExecuteScalar();
}
}
}
#endregion
网页名称:sqlhelper的编写
分享URL:http://azwzsj.com/article/jecigc.html