示例#1
0
 public I3DataOleAda(OleDbConnection con, string sqlStr, I3Command command)
 {
     adapter = new OleDbDataAdapter(sqlStr, con);
     //_com = new OleDbCommandBuilder(_ada);
     if (command == null)
     {
         commandBuilder = new OleDbCommandBuilder(adapter);
     }
     else
     {
         adapter.UpdateCommand = command == null || command.UpdateCommand == null ? null : (OleDbCommand)command.UpdateCommand;
         adapter.DeleteCommand = command == null || command.DeleteCommand == null ? null : (OleDbCommand)command.DeleteCommand;
         adapter.InsertCommand = command == null || command.InsertCommand == null ? null : (OleDbCommand)command.InsertCommand;
         if (adapter.UpdateCommand != null)
         {
             adapter.UpdateCommand.Connection = con;
         }
         if (adapter.DeleteCommand != null)
         {
             adapter.DeleteCommand.Connection = con;
         }
         if (adapter.InsertCommand != null)
         {
             adapter.InsertCommand.Connection = con;
         }
     }
 }
示例#2
0
 public I3DataSqlAda(SqlConnection con, string sqlStr, I3Command command)
 {
     adapter = new SqlDataAdapter(sqlStr, con);
     if (command == null)
     {
         commandBuilder = new SqlCommandBuilder(adapter);
     }
     else
     {
         adapter.UpdateCommand = command == null || command.UpdateCommand == null ? null : (SqlCommand)command.UpdateCommand;
         adapter.DeleteCommand = command == null || command.DeleteCommand == null ? null : (SqlCommand)command.DeleteCommand;
         adapter.InsertCommand = command == null || command.InsertCommand == null ? null : (SqlCommand)command.InsertCommand;
         if (adapter.UpdateCommand != null)
         {
             adapter.UpdateCommand.Connection = con;
         }
         if (adapter.DeleteCommand != null)
         {
             adapter.DeleteCommand.Connection = con;
         }
         if (adapter.InsertCommand != null)
         {
             adapter.InsertCommand.Connection = con;
         }
     }
 }
示例#3
0
        public override I3MsgInfo FillTable(DataTable dataTable, bool clear, string sqlText, DbParameter[] paramList, DbTransaction aTran, I3Command command)
        {
            if (!active)
            {
                return(new I3MsgInfo(false, "连接已断开,无法填充DataTable"));
            }


            if (dataTable.TableName == "")
            {
                dataTable.TableName = Guid.NewGuid().ToString().ToUpper();
            }

            try
            {
                I3DataOleAda tmp  = null;
                bool         have = _tableList.Contains(dataTable);

                if (have)
                {
                    tmp = (I3DataOleAda)_tableList[dataTable];
                    if (clear)
                    {
                        dataTable.Clear();
                    }
                    tmp.SelectCommand.CommandText = sqlText;
                    tmp.SelectCommand.Parameters.Clear();
                    if (paramList != null)
                    {
                        for (int i = 0; i < paramList.Length; i++)
                        {
                            tmp.SelectCommand.Parameters.Add(paramList[i]);
                        }
                    }
                    tmp.Adapter.Fill(dataTable);
                    //tmp.SelectCommand.Parameters.Clear();
                }
                else
                {
                    tmp = new I3DataOleAda(connection, sqlText, command);
                    tmp.SelectCommand.Parameters.Clear();
                    if (paramList != null)
                    {
                        for (int i = 0; i < paramList.Length; i++)
                        {
                            tmp.SelectCommand.Parameters.Add(paramList[i]);
                        }
                    }
                    _tableList.Add(dataTable, tmp);

                    if (aTran != null)
                    {
                        tmp.SelectCommand.Transaction = (OleDbTransaction)aTran;
                    }
                    else
                    {
                        tmp.SelectCommand.Transaction = null;
                    }
                    tmp.Adapter.Fill(dataTable);
                    //tmp.SelectCommand.Parameters.Clear();
                }
                return(I3MsgInfo.Default);
            }
            catch (Exception ex)
            {
                return(new I3MsgInfo(false, ex.Message, ex));
            }
        }
示例#4
0
 public I3MsgInfo FillTable(DataTable dataTable, bool clear, string sqlText, DbTransaction aTran, I3Command command)
 {
     return(FillTable(dataTable, clear, sqlText, null, aTran, command));
 }
示例#5
0
 /// <summary>
 /// 这里由子类来实现,用于填充数据集,clear指示是否清除dataTable中的现有数据
 /// 可以多次调用以填充多个DataTable
 /// 但对于同一个表,在多次填充到不同的数据集中时,请注意避免数据混乱。
 ///
 /// 对于Xml数据源,只能读取一次,除非将Data类的对象释放后重新读取
 ///
 /// 另外,对于Xml数据源,请传递""作为sqlText
 ///
 ///
 /// 在对某个DataTable进行填充,并对它进行修改,如果此时使用DataTable.Clear()
 /// 则SqlCommandBuilder中生成的相应sql语句也会被自动释放
 ///
 /// ArrayList中的对象必须是SqlParameter或者OleDbParameter
 ///
 /// 增加了自定义UpdateCommand、InsertCommand、DeleteCommand支持,说明见修改记录6
 ///
 /// </summary>
 /// <param name="dataTable"></param>
 /// <param name="clear"></param>
 public abstract I3MsgInfo FillTable(DataTable dataTable, bool clear, string sqlText, DbParameter[] paramList, DbTransaction aTran, I3Command command);
示例#6
0
        public override I3MsgInfo FillTable(DataTable dataTable, bool clear, string sqlText, DbParameter[] paramList, DbTransaction aTran, I3Command command)
        {
            if (!active)
            {
                return(new I3MsgInfo(false, "未读取Xml文件,无法填充DataTable"));
            }

            if (dataTable.TableName == "")
            {
                return(new I3MsgInfo(false, "未指定TableName!"));
            }

            //if (clear) dataTable.Clear();//无需清除,XML数据源时始终为全部数据

            if (sqlText == "")
            {
                try
                {
                    int count = dataset.Tables.Count;
                    int j     = -1;
                    for (int i = 0; i < count; i++)
                    {
                        if (dataset.Tables[i].TableName == dataTable.TableName)
                        {
                            j = i;
                            break;
                        }
                    }
                    if (j == -1)
                    {
                        return(new I3MsgInfo(false, "此Xml数据源中没有表" + dataTable.TableName + "的存在"));
                    }
                    count = tablenames.Count; j = -1;
                    for (int i = 0; i < count; i++)
                    {
                        if (tablenames[i].ToString() == dataTable.TableName)
                        {
                            j = i;
                            break;
                        }
                    }
                    if (j != -1)
                    {
                        return(new I3MsgInfo(false, "此Xml数据源中表" + dataTable.TableName + "已被读取"));
                    }

                    dataTable = dataset.Tables[dataTable.TableName];
                    return(I3MsgInfo.Default);
                }
                catch (Exception ex)
                {
                    return(new I3MsgInfo(false, ex.Message, ex));
                }
            }
            else
            {
                return(new I3MsgInfo(false, "当数据源为Xml文件时,填充DataTable不需要sql语句!"));
            }
        }