码迷,mamicode.com
首页 > 其他好文 > 详细

底层的增删查改

时间:2020-01-13 13:14:01      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:min   ring   查询   new   password   use   list   OLE   region   

#region 助手类
public class Dbhelper
{

static string sqlConnectionString = @"Database=CMS;Server=42.159.145.218,1401;User ID =azureadmin; Password =P@ss1234567890;";

//新增
public object Insert<T>(string sql, T t)
{
try
{
object result;
using (IDbConnection connection = new SqlConnection(sqlConnectionString))
{
result = connection.Execute(sql, t);
}
return result;
}
catch (Exception ex)
{
Console.Write(ex.Message);
return -999;
}

}

public object BatchInsert<T>(string sql, List<T> list)
{
try
{
object result;
using (IDbConnection connection = new SqlConnection(sqlConnectionString))
{
result = connection.Execute(sql, list);
}
return result;
}
catch (Exception ex)
{
Console.Write(ex.Message);
return -999;
}
}
//删除
public int Delete<T>(string sql, T t)
{

try
{
int result;
using (IDbConnection connection = new SqlConnection(sqlConnectionString))
{
result = connection.Execute(sql, t);
}
return result;
}
catch
{
return -999;
}
}
//查询
public object Search<T>(string sql, T t)
{
try
{
object result;
using (IDbConnection connection = new SqlConnection(sqlConnectionString))
{
result = connection.Execute(sql, t);
}
return result;
}
catch (Exception ex)
{
return ex.Message;
}
}
//修改
public int Update<T>(string sql, T t)
{
try
{
int result;
using (IDbConnection connection = new SqlConnection(sqlConnectionString))
{
result = connection.Execute(sql, t);
}
return result;
}
catch
{
return -999;
}
}


//查询
public List<T> SearchData<T>(string sql, object obj)
{
IDbConnection connection = new SqlConnection(sqlConnectionString);
return connection.Query<T>(sql, obj).ToList();
}

 

}
#endregion

底层的增删查改

标签:min   ring   查询   new   password   use   list   OLE   region   

原文地址:https://www.cnblogs.com/ning-xiaowo/p/12186471.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!