public static partial class 【这里是插入方法】
{
public static 【返回对象】 【方法名】(【数据对象】)
{
string sql =
"INSERT 【表名】(【字段】)" +
"VALUES (@【参数名】)";
sql += " ; SELECT @@IDENTITY";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@【参数名1】",【参数1】),
new SqlParameter("@【参数名n】",【参数n】)
};
int newId = DBHelper.GetScalar(sql, para);
return 【通过ID查询的方法或直接返回对象】 (newId);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
public static void 【通过对象删除方法名】(【传入对象】)
{
【通过ID删除方法】( 【传入对象.ID】);
}
public static void 【通过ID删除方法名】(【对象ID】)
{
string sql = "DELETE 【表名】WHERE 【ID字段】= @【参数】";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@【参数】", 【对象ID】)
};
DBHelper.ExecuteCommand(sql, para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
public static void 【通过对象修改表的方法名】(【对象】)
{
string sql =
"UPDATE 【表名】" +
"SET " +
"【字段1】= @【参数1】, " +
"【字段2】= @【参数2】, " +
"............................ " +
"【字段n】= @【参数n】" +
"WHERE 【条件】= @【参数】";
try
{
SqlParameter[] para = new SqlParameter[]
{
new SqlParameter("@【参数名1】",【参数1】),
new SqlParameter("@【参数名n】",【参数n】)
};
DBHelper.ExecuteCommand(sql, para);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
public static IList<【对象】> 【查询所有数据方法名】()
{
string sqlAll = "SELECT * FROM 【表名】";
return 【通过查询语句查询方法名】( sqlAll );
}
private static IList<【对象】> 【通过查询语句查询方法名】( string safeSql )
{
List<【对象】> list = new List<【对象】>();
try
{
DataTable table = DBHelper.GetDataSet( safeSql );
foreach (DataRow row in table.Rows)
{
【对象】【自定义对象名】= new 【对象】();
【对象字段】= (【数据类型】)row["【字段名】"];
list.Add(【对象】);
}
return list;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
private static IList<【对象】> 【通过查询语句带参数的方式查询方法名】( string sql, params SqlParameter[] values )
{
List<【对象】> list = new List<【对象】>(); try
{
DataTable table = DBHelper.GetDataSet( sql, values );
foreach (DataRow row in table.Rows)
{
【对象】【自定义对象名】= new 【对象】();
【对象字段】= (【数据类型】)row["【字段名】"];
list.Add(【对象】);
}
return list;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw e;
}
}
2016



被折叠的 条评论
为什么被折叠?



