示例#1
0
        public static void GetFileFromField(ADODB.Field Fld, string FullPath)
        {
            byte[] aChunks = new byte[Fld.ActualSize];
            aChunks = (byte[])Fld.GetChunk(Fld.ActualSize);

            CFile.WriteByteToFile(FullPath, aChunks);
        }
        private void UpdateADODBRecordset_from_ADODataTable(DataTable inTable, ref ADODB.Recordset adoRs)
        {
            ADODB.Fields adoFields = adoRs.Fields;
            System.Data.DataColumnCollection inColumns = inTable.Columns;
            //Delete
            if (adoRs.RecordCount > 0)
            {
                adoRs.MoveFirst();
            }
            while (!adoRs.EOF)
            {
                adoRs.Delete();
                adoRs.MoveNext();
            }
            //Add
            foreach (DataRow dr in inTable.Rows)
            {
                // Proceso las que no estan borradas
                if (dr.RowState != DataRowState.Deleted)
                {
                    adoRs.AddNew(System.Reflection.Missing.Value,
                                 System.Reflection.Missing.Value);

                    for (int columnIndex = 0; columnIndex < inColumns.Count; columnIndex++)
                    {
                        ADODB.Field field = adoFields[columnIndex];
                        try
                        {
                            adoFields[columnIndex].Value = dr[columnIndex];
                        }
                        catch (Exception ex)
                        {
                            string message = string.Format("Error al actualizar la columna {0}.{1}: {2}", inTable.TableName, field.Name, ex.Message);
                            throw new XTangoException(message);
                        }
                    }
                }
            }
        }
示例#3
0
        private void writeRecordsetFieldToCell(ADODB.Field field, int row, int col)
        {
            try {
                // Don't do anything if the field value is empty
                if (field.Value + "" != "")
                {
                    Range cellToWriteTo = new Range(row, col, _worksheet, _document);

                    switch (field.Type)
                    {
                    case ADODB.DataTypeEnum.adInteger:
                        cellToWriteTo.Value = Int32.Parse(field.Value.ToString());
                        break;

                    case ADODB.DataTypeEnum.adSmallInt:
                        cellToWriteTo.Value = Int16.Parse(field.Value.ToString());
                        break;

                    case ADODB.DataTypeEnum.adVarChar:
                        cellToWriteTo.Value = field.Value.ToString();
                        break;

                    case ADODB.DataTypeEnum.adDBDate:
                        cellToWriteTo.Value = DateTime.Parse(field.Value.ToString());
                        break;

                    // The default case will probably throw an error, but info will be written
                    // to the sheet so a new type can be added.
                    default:
                        _document.SetCellValue(row, col, (string)field.Value);
                        break;
                    }
                }
            }
            catch (Exception e) {
                _document.SetCellValue(row, col, "Error writing value (" + field.Value + ") of type : "
                                       + field.Type + ".  Exception: " + e.Message);
            }
        }