Пример #1
0
        /// <summary>
        /// �������ݱ�������ݷ��ʶ���
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="SQL"></param>
        /// <param name="DB"></param>
        /// <returns></returns>
        private int UpdateDataTable(DataTable dt, string SQL, DMEDb_CommonDB DB)
        {
            string ParaChar = GetDBParaChar(DB);
            SQL = SQL.Replace("@@", ParaChar);
            int count = 0;

            foreach (DataRow dr in dt.Rows)
            {
                IDataParameter[] paras = new IDataParameter[dt.Columns.Count];
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    paras[i] = DB.GetParameter(ParaChar + dt.Columns[i].ColumnName, dr[i]);
                }
                count += DB.ExecuteNonQuery(SQL, CommandType.Text, paras);
                if (DB.ErrorMessage != "")
                    throw new Exception(DB.ErrorMessage);
            }

            return count;
        }
Пример #2
0
        /// <summary>
        /// �������ݼ��е��ֶε�����Դ��
        /// </summary>
        /// <param name="sDs">Դ���ݼ�</param>
        /// <param name="tableName">Ҫ���µı�</param>
        /// <param name="fieldName">Ҫ���µ��ֶ�</param>
        /// <param name="fieldValue">�ֶε�ֵ</param>
        /// <param name="pkName">��������</param>
        /// <param name="DB">���ݷ��ʶ���</param>
        /// <returns></returns>
        public int UpdateField(DataSet sDs, string tableName, string fieldName, object fieldValue, string pkName, DMEDb_CommonDB DB)
        {
            DataSet ds = sDs.Copy();
            DataTable dt = ds.Tables[tableName];
            fieldName = fieldName.ToUpper();
            pkName = pkName.ToUpper();

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                string colName = dt.Columns[i].ColumnName.ToUpper();
                if (colName == fieldName || colName == pkName)
                    continue;
                dt.Columns.Remove(colName);
                i = 0;//����Ԫ��λ�ÿ����Ѿ�Ǩ�ƣ�������Ҫ���´�ͷ��ʼ����
            }
            dt.PrimaryKey = new DataColumn[] { dt.Columns[pkName] };
            foreach (DataRow dr in dt.Rows)
            {
                dr[fieldName] = fieldValue;
            }

            int updCount = UpdateDataSet(ds, DB);
            return updCount;
        }
Пример #3
0
 /// <summary>
 /// ��ȡ�ض����ݿ�����ַ�
 /// </summary>
 /// <param name="DB">���ݿ�����</param>
 /// <returns></returns>
 private static string GetDBParaChar(DMEDb_CommonDB DB)
 {
     return DB is DMEDb_Oracle ? ":" : "@";
 }
Пример #4
0
 /// <summary>
 /// �������ݼ��������ݷ��ʶ���
 /// </summary>
 /// <param name="ds">���ݼ�</param>
 /// <param name="DB">���ݷ��ʶ���</param>
 /// <returns></returns>
 public int UpdateDataSet(DataSet ds, DMEDb_CommonDB DB)
 {
     int count = 0;
     foreach (DataTable dt in ds.Tables)
     {
         if (dt.PrimaryKey.Length > 0)
         {
             count += UpdateDataTable(dt, GetSqlUpdate(dt), DB);
             _msg = "�Ѿ����¼�¼" + count + "��";
         }
         else
         {
             count += UpdateDataTable(dt, GetSqlInsert(dt), DB);
             _msg = "�Ѿ������¼" + count + "��";
         }// end if
     }//end for
     return count;
 }
Пример #5
0
 /// <summary>
 /// ����������Ϣ������Դ��ѯ���ݱ�����ݼ���
 /// </summary>
 /// <param name="fields">�ֶ��б�</param>
 /// <param name="tableName">����Դ�еı�����</param>
 /// <param name="pkNames">������������</param>
 /// <param name="pkValues">����ֵ���飬�������������Ӧ</param>
 /// <param name="DB">���ݷ��ʶ���</param>
 /// <returns></returns>
 public DataSet SelectDataSet(string fields, string tableName, string[] pkNames, object[] pkValues, DMEDb_CommonDB DB)
 {
     string ParaChar = GetDBParaChar(DB);
     string sqlSelect = "SELECT " + fields + " FROM " + tableName + " WHERE 1=1 ";
     IDataParameter[] paras = new IDataParameter[pkNames.Length];
     for (int i = 0; i < pkNames.Length; i++)
     {
         sqlSelect += " And " + pkNames[i] + "=" + ParaChar + pkNames[i];
         paras[i] = DB.GetParameter(ParaChar + pkNames[i], pkValues[i]);
     }
     DataSet ds = DB.ExecuteDataSet(sqlSelect, CommandType.Text, paras);
     ds.Tables[0].TableName = tableName;
     return ds;
 }
Пример #6
0
 /// <summary>
 /// �������ݼ�����ָ���ı��У����ݱ��е�ָ���е�ֵ������Դ��ɾ������,�����ݷ��ʶ���
 /// </summary>
 /// <param name="ds">���ݼ�</param>
 /// <param name="tableName">������</param>
 /// <param name="columnName">����</param>
 /// <param name="DB">���ݷ��ʶ���</param>
 /// <returns></returns>
 public int DeleteDataSet(DataSet ds, string tableName, string columnName, DMEDb_CommonDB DB)
 {
     DataTable dt = ds.Tables[tableName];
     string ParaChar = GetDBParaChar(DB);
     int count = 0;
     string sqlDelete = "DELETE FROM " + tableName + " WHERE " + columnName + "=" + ParaChar + columnName;
     foreach (DataRow dr in dt.Rows)
     {
         IDataParameter[] paras = { DB.GetParameter(ParaChar + columnName, dr[columnName]) };
         count += DB.ExecuteNonQuery(sqlDelete, CommandType.Text, paras);
         if (DB.ErrorMessage != "")
             throw new Exception(DB.ErrorMessage);
         if (count >= dt.Rows.Count) break;
     }
     return count;
 }
Пример #7
0
 /// <summary>
 /// �������ݿ�ʵ����ȡ���ݿ�����ö��
 /// </summary>
 /// <param name="db"></param>
 /// <returns></returns>
 public static DMEDb_DBMSType GetDBMSType(DMEDb_CommonDB db)
 {
     if (db != null)
     {
         if (db is DMEDb_Access )
             return DMEDb_DBMSType.Access ;
         if (db is DMEDb_SqlServer)
             return DMEDb_DBMSType.SqlServer;
         if (db is DMEDb_Oracle)
             return DMEDb_DBMSType.Oracle;
         if (db is DMEDb_OleDb)
             return DMEDb_DBMSType.UNKNOWN;
         if (db is DMEDb_Odbc)
             return DMEDb_DBMSType.UNKNOWN;
     }
     return DMEDb_DBMSType.UNKNOWN;
 }
Пример #8
0
 public DMEDb_EntityCommand(DMEDb_EntityBase entity, DMEDb_CommonDB db)
 {
     this.currEntity = entity;
     this.currDb = db;
 }