示例#1
0
        //DataTable转RecordSet
        public Recordset DsToRs(DataTable table)
        {
            Recordset rs = new RecordsetClass();

            System.Array ArrA = System.Array.CreateInstance(typeof(string), table.Columns.Count);

            foreach (DataColumn dc in table.Columns)
            {
                ArrA.SetValue(dc.ColumnName, dc.Ordinal);
                rs.Fields._Append(dc.ColumnName, GetDataType(dc.DataType), -1, FieldAttributeEnum.adFldIsNullable);
            }
            rs.Open(Missing.Value, Missing.Value, CursorTypeEnum.adOpenUnspecified, LockTypeEnum.adLockUnspecified, -1);
            //rs.Open(null,null, CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockOptimistic, 0);
            // int i = 0;
            foreach (DataRow dr in table.Rows)
            {
                rs.AddNew(Missing.Value, Missing.Value); //object o;
                                                         // rs.AddNew(rs.Fields.,dr.ItemArray);

                //rs.AddNew(ArrA, dr.ItemArray);
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    rs.Fields[i].Value = dr[i];
                }
            }
            return(rs);
        }
示例#2
0
        private static Recordset ConvertDataGridViewToRecordSet(DataGridView dgv)
        {
            Recordset result = new RecordsetClass();

            foreach (DataGridViewColumn col in dgv.Columns)
            {
                if (col.Visible)
                {
                    result.Fields._Append(col.HeaderText, GetDataType(col.ValueType), -1, FieldAttributeEnum.adFldIsNullable);
                }
            }

            result.Open(miss, miss, CursorTypeEnum.adOpenUnspecified, LockTypeEnum.adLockUnspecified, -1);

            foreach (DataGridViewRow row in dgv.Rows)
            {
                result.AddNew(miss, miss);
                int i = 0;

                foreach (DataGridViewColumn col in dgv.Columns)
                {
                    if (col.Visible)
                    {
                        result.Fields[i].Value = row.Cells[col.Name].Value;
                        i++;
                    }
                }
            }

            return(result);
        }
示例#3
0
        //Missing的命名空间using System.Reflection;
        public Recordset ConvertDataTableToRecordset(DataTable table)
        {
            Recordset rs = new RecordsetClass();

            foreach (DataColumn dc in table.Columns)
            {
                rs.Fields._Append(dc.ColumnName, GetDataType(dc.DataType), -1, FieldAttributeEnum.adFldIsNullable);
            }
            rs.Open(Missing.Value, Missing.Value, CursorTypeEnum.adOpenUnspecified, LockTypeEnum.adLockUnspecified, -1);
            foreach (DataRow dr in table.Rows)
            {
                rs.AddNew(Missing.Value, Missing.Value); object o;
                for (int i = 0; i < table.Columns.Count; i++)
                {
                    rs.Fields[i].Value = dr[i];
                    o = rs.Fields[i].Value;
                }
            }
            return(rs);
        }
示例#4
0
        private static Recordset ConvertDataTableToRecordset(DataTable table)
        {
            Recordset result = new RecordsetClass();

            foreach (DataColumn col in table.Columns)
            {
                result.Fields._Append(col.ColumnName, GetDataType(col.DataType), -1, FieldAttributeEnum.adFldIsNullable);
            }

            result.Open(Missing.Value, Missing.Value, CursorTypeEnum.adOpenUnspecified, LockTypeEnum.adLockUnspecified, -1);

            foreach (DataRow row in table.Rows)
            {
                result.AddNew(Missing.Value, Missing.Value);

                for (int i = 0; i < table.Columns.Count; i++)
                {
                    result.Fields[i].Value = row[i];
                }
            }

            return(result);
        }