2023年6月21日发(作者:)
SQLHelper的基本使⽤⾸先是下载SQLHelper,修改SQLHelper 的连接配置信息,private static string GetConnection() { string strConnection = ""; try { strConnection = tionStrings["ServerConnectionString"].ConnectionString; if (OrEmpty(strConnection)) throw new Exception("ConnectionString is NullorEmpty!"); else return strConnection; } catch (Exception e) { throw new Exception("Error in GetConnectionString Source:" + ng() + " Message:" + ng()); } }ExecuteScalar
⽤来执⾏⼀⾏SQL语句,有多个重载函数;可以依据⾃⼰的需要配置:返回值是个Object 类型,可以执⾏的类型包括,sql 语句,存储过程,public string Add(_Info groupobj) { try { SqlParameter[] parameters ={ new SqlParameter("@GName",), new SqlParameter("@GOrder",) }; string commandText = "if exites (select 1 from Group_Info where GName=@GName)" + "begin" + " select 'exists';" + "end" + "else " + "begin" + " insert Group_Info (GName,GOrder) values (@GName,@GOrder)" + " select 'ok';"+ "end"; return eScalar(commandText, parameters).ToString(); } catch (Exception ex) { rrorLog(ex); return "error"; } }ExecuteNonQuery 的使⽤可以⽤来执⾏,新增,修改,删除,返回值为int 类型,表⽰影响的⾏数。public int Update(_Info groupobj, int gid) { SqlParameter[] parameters = {
new SqlParameter("@ID",gid), new SqlParameter("@GName",), new SqlParameter("@GOrder",) }; string commandText = "update Group_Info set GName=@GName,GOrder=@GOrder where id=@ID"; try { return eNonQuery(commandText, parameters); } catch (Exception ex) { rrorLog(ex); return 0; } }
2023年6月21日发(作者:)
SQLHelper的基本使⽤⾸先是下载SQLHelper,修改SQLHelper 的连接配置信息,private static string GetConnection() { string strConnection = ""; try { strConnection = tionStrings["ServerConnectionString"].ConnectionString; if (OrEmpty(strConnection)) throw new Exception("ConnectionString is NullorEmpty!"); else return strConnection; } catch (Exception e) { throw new Exception("Error in GetConnectionString Source:" + ng() + " Message:" + ng()); } }ExecuteScalar
⽤来执⾏⼀⾏SQL语句,有多个重载函数;可以依据⾃⼰的需要配置:返回值是个Object 类型,可以执⾏的类型包括,sql 语句,存储过程,public string Add(_Info groupobj) { try { SqlParameter[] parameters ={ new SqlParameter("@GName",), new SqlParameter("@GOrder",) }; string commandText = "if exites (select 1 from Group_Info where GName=@GName)" + "begin" + " select 'exists';" + "end" + "else " + "begin" + " insert Group_Info (GName,GOrder) values (@GName,@GOrder)" + " select 'ok';"+ "end"; return eScalar(commandText, parameters).ToString(); } catch (Exception ex) { rrorLog(ex); return "error"; } }ExecuteNonQuery 的使⽤可以⽤来执⾏,新增,修改,删除,返回值为int 类型,表⽰影响的⾏数。public int Update(_Info groupobj, int gid) { SqlParameter[] parameters = {
new SqlParameter("@ID",gid), new SqlParameter("@GName",), new SqlParameter("@GOrder",) }; string commandText = "update Group_Info set GName=@GName,GOrder=@GOrder where id=@ID"; try { return eNonQuery(commandText, parameters); } catch (Exception ex) { rrorLog(ex); return 0; } }
发布评论