谁有自己写的数据库类,分享一下嘛

解决方案 »

  1.   

    给我发过来好吗?
    [email protected]
      

  2.   

    你是指SQLHelper之类的东西吗??
      

  3.   

    不是我要私下交易之类的,分不给我也无所谓,这分也没用,只是我没地方上传,谁给我提供一下?需要的朋友看看http://www.cnblogs.com/cnlamar/archive/2004/10/13/51923.aspx如果是这样的,我给你们发,有人能提供空间,我就给上传,OK?
      

  4.   

    nhibernate试用一下这个,不一样的感觉。
      

  5.   

    我想要
    [email protected]
    谢谢拉
      

  6.   

    微软有一个data access application block啊,你是否说这个哦
      

  7.   

    我自己也写了几个,比如在我的程序里调用存储过程
                               DBMgr Dbmanager=new DBMgr();
    Hashtable hashtable=new Hashtable();
    hashtable.Add("@bookid",bookid);
    hashtable.Add("@bookname",bookname);
    hashtable.Add("@bookcatalog",bookcatalog);
    hashtable.Add("@author",author);
    hashtable.Add("@starttime",starttime);
    hashtable.Add("@endtime",endtime);
    DataSet ds=Dbmanager.ExecuteStoredProcedure                ("sp_QueryBook",hashtable);
    return ds;
    增加操作:
    DBMgr mgr=new DBMgr();
    string sqlAdd="insert into CardSellLog(WaterNum,CardId,UserId,Price)"
    +" values('{0}','{1}','{2}',{3})";
    string temp=string.Format(sqlAdd,tblAdd.WaterNum,tblAdd.CardId,tblAdd.UserId,tblAdd.Price);
    mgr.ExecuteNonQuery(temp);这些是不用写代码,我自己编写了一个程序,自动产生这些东西,
      

  8.   

    我有一份,不能调用存储过程,哪位有调用存储过程的,可否分享一下?
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;namespace DbBase
    {
    /// <summary>
    /// base.
    /// </summary>
    public abstract class Base
    { #region "Fields of base calss" /// <summary>
    /// connecting to Database
    /// </summary>
    protected static string strConn = ConfigurationSettings.AppSettings["strConnection"]; /// <summary>
    /// SQL command
    /// </summary>
    protected static string strSQL; #endregion
    #region "Properties of base class"
    private int m_ID;
    private string m_Name; /// <summary>
    /// Property:ID
    /// </summary>
    public int ID
    {
    get
    {
    return m_ID;
    }
    set
    {
    m_ID = value;
    }
    }
    /// <summary>
    /// name
    /// </summary>
    public string Name
    {
    get
    {
    return m_Name;
    }
    set
    {
    m_Name = value;
    }
    } #endregion
    #region "Functions of base class"
    public Base()
    {
    //
    // TODO: Add constructor logic here
    //
    } /// <summary>
    /// executing SQL commands
    /// </summary>
    /// <param name="strSQL">string</param>
    /// <returns>return int</returns>
    protected int ExecuteSql(string strSQL)
    {
    SqlConnection myCn = new SqlConnection(strConn);
    SqlCommand myCmd = new SqlCommand(strSQL,myCn);
    try
        {
    myCn.Open();
    myCmd.ExecuteNonQuery();
    return 0;
    }
    catch(System.Data.SqlClient.SqlException e)
    {
    throw new Exception(e.Message);
    }
    finally
    {
    myCmd.Dispose();
    myCn.Close();
    }
    }
    /// <summary>
    ///executing SQL commands
    /// </summary>
    /// <param name="strSQL">要执行的SQL语句,为字符串类型string</param>
    /// <returns>返回执行情况,整形int</returns>
    protected int ExecuteSqlEx(string strSQL)
    {
    SqlConnection myCn = new SqlConnection(strConn);
    SqlCommand myCmd = new SqlCommand(strSQL,myCn);

    try
    {
    myCn.Open();
    SqlDataReader myReader = myCmd.ExecuteReader();
    if(myReader.Read())
    {
    return 0;
    }
    else
    {
    throw new Exception("Value Unavailable!");
    }
    }
    catch(System.Data.SqlClient.SqlException e)
    {
    throw new Exception(e.Message);
    }
    finally
    {
    myCmd.Dispose();
    myCn.Close();
    }
    }
    /// <summary>
    /// get dataset
    /// </summary>
    /// <param name="strSQL">(string)</param>
    /// <returns>(DataSet)</returns>
    protected DataSet ExecuteSql4Ds(string strSQL)
    {
    SqlConnection myCn = new SqlConnection(strConn);
    try
    {
    myCn.Open();
    SqlDataAdapter sda = new SqlDataAdapter(strSQL,myCn);
    DataSet ds = new DataSet("ds");
    sda.Fill(ds);
    return ds;
    }
    catch(System.Data.SqlClient.SqlException e)
    {
    throw new Exception(e.Message);
    }
    finally
    {
    myCn.Close();
    }
    }
    /// <summary>
    /// get single value
    /// </summary>
    /// <param name="strSQL">(string)</param>
    /// <returns>(int)</returns>
    protected int ExecuteSql4Value(string strSQL)
    {
    SqlConnection myCn = new SqlConnection(strConn);
    SqlCommand myCmd = new SqlCommand(strSQL,myCn);
    try
    {
    myCn.Open();
    object r = myCmd.ExecuteScalar();
    if(Object.Equals(r,null))
    {
    throw new Exception("value unavailable!");
    }
    else
    {
    return (int)r;
    }
    }
    catch(System.Data.SqlClient.SqlException e)
    {
    throw new Exception(e.Message);
    }
    finally
    {
    myCmd.Dispose();
    myCn.Close();
    }
    }
    /// <summary>
    /// get object
    /// </summary>
    /// <param name="strSQL">(string)</param>
    /// <returns>(object)</returns>
    protected object ExecuteSql4ValueEx(string strSQL)
    {
    SqlConnection myCn = new SqlConnection(strConn);
    SqlCommand myCmd = new SqlCommand(strSQL,myCn);
    try
    {
    myCn.Open();
    object r = myCmd.ExecuteScalar();
    if(Object.Equals(r,null))
    {
    throw new Exception("object unavailable!");
    }
    else
    {
    return r;
    }
    }
    catch(System.Data.SqlClient.SqlException e)
    {
    throw new Exception(e.Message);
    }
    finally
    {
    myCmd.Dispose();
    myCn.Close();
    }
    }
    /// <summary>
    /// execute multipul SQL commands 
    /// </summary>
    /// <param name="strSQLs">string</param>
    /// <returns>int</returns>
    protected int ExecuteSqls(string[] strSQLs)
    {
    SqlConnection myCn = new SqlConnection(strConn);
    SqlCommand myCmd = new SqlCommand();
    int j=strSQLs.Length; try
    {
    myCn.Open();
    }
    catch(System.Data.SqlClient.SqlException e)
    {
    throw new Exception(e.Message);
    }
    SqlTransaction myTrans = myCn.BeginTransaction(); try
    {
    myCmd.Connection = myCn;
    myCmd.Transaction = myTrans; foreach(string str in strSQLs)
    {
    myCmd.CommandText = str;
    myCmd.ExecuteNonQuery();
    }
    myTrans.Commit();
    return 0;
    }
    catch(System.Data.SqlClient.SqlException e)
    {
    myTrans.Rollback();
    throw new Exception(e.Message);
    }
    finally
    {
    myCmd.Dispose();
    myCn.Close();
    }
    } #endregion
    }
    }
      

  9.   

    data access application block就可以呀,
    建议csdn要是可以弄些空间来上传就好了.
      

  10.   

    如 happyjun2000(蓝色游侠∮NET) 说用data access application block。
    如果有特殊的需要可以自己改一下就可以了.
      

  11.   

    这是我自己写的,相关的应用如下:
    --------------------------------------------
    namespace CarsSys.Users
    {
    [HFSoft.Data.DomainObjects.Attributes.ObjectInfoAttributes("T_Users")]
    public class User:HFSoft.Data.DomainObjects.EntityObjectBase
    {
    #region Const
    /// <summary>
    /// 同一名称的类别已经存在
    /// </summary>
    public const string ERROR_INSERT_REPEAT ="同一用户编号的用户信息已经存在!";
    /// <summary>
    /// 实体对象为空值
    /// </summary>
    public const string ERROR_OBJECT_NULL ="用户信息对象为空!";
    /// <summary>
    /// 类别数据表处理错误
    /// </summary>
    public const string ERROR_ALL ="用户信息表处理错误!";
    #endregion
    public User()
    {
    }
    private object mUserCode = null;
    public const string F_UserCode = "UserCode";
    [HFSoft.Data.DomainObjects.Attributes.FieldInfoAttributes("UserCode",PrimaryKey = true)]
    public object UserCode
    {
    get
    {
    return mUserCode;
    }
    set {
    mUserCode = value;
    }
    }
    private object mUserName = null;
    public const string F_UserName = "UserName";
    [HFSoft.Data.DomainObjects.Attributes.FieldInfoAttributes("UserName")]
    public object UserName
    {
    get
    {
    return mUserName;
    }
    set
    {
    mUserName = value;
    }
    }
    private object mUserPWD = null;
    public const string F_UserPWD = "UserPWD";
    [HFSoft.Data.DomainObjects.Attributes.FieldInfoAttributes("UserPWD")]
    public object UserPWD
    {
    get
    {
    return mUserPWD;
    }
    set
    {
    mUserPWD = value;
    }
    }
    private object mDept = null;
    public const string F_Dept = "Dept";
    [HFSoft.Data.DomainObjects.Attributes.FieldInfoAttributes("Dept")]
    public object Dept
    {
    get
    {
    return mDept;
    }
    set
    {
    mDept = value;
    }
    }
    private object mPhone = null;
    public const string F_Phone = "Phone";
    [HFSoft.Data.DomainObjects.Attributes.FieldInfoAttributes("Phone")]
    public object Phone
    {
    get
    {
    return mPhone;
    }
    set
    {
    mPhone = value;
    }
    }
    private object mEmail = null;
    public const string F_Email = "Email";
    [HFSoft.Data.DomainObjects.Attributes.FieldInfoAttributes("Email")]
    public object Email
    {
    get
    {
    return mEmail;
    }
    set
    {
    mEmail = value;
    }
    }
    private object mRe = null;
    public const string F_Re = "Re";
    [HFSoft.Data.DomainObjects.Attributes.FieldInfoAttributes("Re")]
    public object Re
    {
    get
    {
    return mRe;
    }
    set
    {
    mRe = value;
    }
    }
    private object mFilialeCode = null;
    public const string F_FilialeCode = "FilialeCode";
    [HFSoft.Data.DomainObjects.Attributes.FieldInfoAttributes("FilialeCode")]
    public object FilialeCode
    {
    get
    {
    return mFilialeCode;
    }
    set
    {
    mFilialeCode = value;
    }
    }
    }
    }
    ----------------------------
    namespace CarsSys.Users
    {
    public class Query : UserBase
    {
    public System.Data.DataSet Items
    {
    get
    {
    return mItems;
    }
    set
    {
    mItems = value;
    }
    }
    private System.Data.DataSet mItems;
    public override void RunBusiness()
    {
    this.Items = this.DataUnit.QueryDataSet(EntityType,Filters);
    base.RunBusiness ();
    } }
    }
    namespace CarsSys.Users
    {
    public class QueryByCode : UserBase
    {
    public CarsSys.Users.User Item
    {
    get
    {
    return mItem;
    }
    set
    {
    mItem = value;
    }
    }
    public string UserCode
    {
    get
    {
    return mUserCode;
    }
    set
    {
    mUserCode = value;
    }
    }
    private CarsSys.Users.User mItem;
    private string mUserCode;
    public override void RunBusiness()
    {
    Filters.EqualTo(User.F_UserCode,UserCode);
    this.Item = this.DataUnit.GetObject(EntityType,Filters) as User;
    base.RunBusiness ();
    } }
    }
    namespace CarsSys.Users
    {
    public class UserLogin : QueryByCode
    {
    public string UserPwd
    {
    get
    {
    return mUserPwd;
    }
    set
    {
    mUserPwd = value;
    }
    }
    private string mUserPwd;
    public override void RunBusiness()
    {
    Filters.EqualTo(User.F_UserPWD,UserPwd);
    base.RunBusiness ();
    } }
    }