DBHelper 方法集合

2021-06-22 10:59:17 字數 3740 閱讀 2583

using system;   

using system.collections.generic;

using system.text;

using system.data.sqlclient;

using system.data;

using system.configuration;

using bookshop.models;

namespace bookshop.dal

else if (connection.state == system.data.connectionstate.closed)

else if (connection.state == system.data.connectionstate.broken)

return connection;

}

} #region 增,刪,改executenonquery

/// /// 單個資料增,刪,改

///

///

///

public static int executecommand(string safesql)

}

catch (sqlexception ex)

} #endregion

#region 帶引數的增,刪,改executenonquery

/// /// 帶多個引數的增,刪,改

///

///

///

///

public static int executecommand(string safesql, params sqlparameter values)

}

catch (sqlexception ex)

} #endregion

#region 帶引數的增,刪,改executenonquery

/// /// 帶多個引數的增,刪,改

///

///

///

///

public static int executecommand(string safesql, commandtype type, params sqlparameter values)

}

catch (sqlexception ex)

} #endregion

#region 帶引數的增,刪,改executenonquery (special)

/// /// 帶多個引數的增,刪,改

///

///

///

///

public static int executecommand(string safesql,commandtype type, int index)

}

catch (sqlexception ex)

} #endregion

#region 查詢語句executescalar

/// /// 查單個值

///

///

///

public static int getscalar(string safesql)

}

catch (sqlexception ex)

} #endregion

#region 帶引數的查詢語句executescalar

/// /// 帶引數的查詢語句

///

///

///

///

public static int getscalar(string sql, params sqlparameter values)

}

catch (sqlexception ex)

} #endregion

#region 帶執行型別的executescalar

/// /// 帶執行型別的executescalar

///

///

///

///

///

public static int getscalar(string sql, commandtype type, params sqlparameter values)

}

catch (sqlexception ex)

} #endregion

#region 返回datareader

/// /// 查詢表,獲取多個記錄

///

///

///

public static sqldatareader getreader(string safesql)

}

catch (sqlexception ex)

} #endregion

#region 帶引數datareader

/// /// 帶引數的-查詢表,獲取多個記錄

///

///

///

///

public static sqldatareader getreader(string sql, params sqlparameter values)

}

catch (sqlexception)

} #endregion

#region 返回datareader ,語句,型別,引數

/// /// 查詢表,獲取多個記錄---語句,型別,引數

///

///

///

///

///

public static sqldatareader getreader(string safesql, commandtype cmdtype, params sqlparameter values)

}

catch (sqlexception ex)

} #endregion

#region 返回datatable

/// /// 返回datatable

///

///

///

public static datatable getdataset(string safesql)

#endregion

#region 返回datatable ,帶引數

/// /// 返回datatable ,帶引數使用

///

///

///

///

public static datatable getdataset(string sql, params sqlparameter values)

#endregion

}

}

DbHelper資料操作類

using system using system.data using system.data.common using system.configuration public class dbhelper public dbhelper string connectionstring publi...

微軟通用的DBHelper

view plain using system using system.configuration using system.data using system.data.common using system.data.oledb using system.data.sqlclient name...

原創,分享 DbHelper 續

一直在想怎麼樣才能讓dbhelper更簡單,更靈活,更僵化。終於我發布了第乙個開源版本的dbhelper.此helper將使用system.data.dbhelper作為命名空間。採用內部驅動與內容session的方式來進行管理。而作為使用者,你只需要作兩件事情。1 註冊乙個驅動 2 繼承dal建立...