////////////////////////////////////////////////////
        protected virtual OleDbParameter GetParametreFor(CInfoChampTable champ, DataRowVersion version, ParameterDirection direction)
        {
            OleDbParameter parametre = new OleDbParameter(GetNomParametreFor(champ, version), COleDbTypeConvertor.GetTypeOleDbFromType(champ.TypeDonnee));

            if ((parametre.DbType == DbType.String || parametre.DbType == DbType.AnsiString) && !champ.IsLongString)
            {
                parametre.Size = champ.Longueur;
            }
            parametre.Direction     = direction;
            parametre.SourceColumn  = champ.NomChamp;
            parametre.SourceVersion = version;
            return(parametre);
        }
Пример #2
0
        ///////////////////////////////////////////////////////////////////////
        private CResultAErreur CreateData(DataTable table)
        {
            CResultAErreur result = CResultAErreur.True;

            try
            {
                OleDbCommand command = new OleDbCommand();
                command.Connection  = m_connection;
                command.Transaction = m_transaction;
                string strValues  = "";
                string strRequete = "insert into " + table.TableName + " (";

                int nParam = 1;
                foreach (DataColumn col in table.Columns)
                {
                    if (GetStringOleDbForColumn(col) != null)
                    {
                        strRequete += col.ColumnName + ",";
                        strValues  += "@" + nParam.ToString() + ",";
                        nParam++;
                    }
                }
                strValues           = strValues.Substring(0, strValues.Length - 1);
                strRequete          = strRequete.Substring(0, strRequete.Length - 1);
                strRequete         += ") values (" + strValues + ")";
                command.CommandText = strRequete;
                nParam = 1;
                foreach (DataRow row in table.Rows)
                {
                    command.Parameters.Clear();
                    foreach (DataColumn col in table.Columns)
                    {
                        if (GetStringOleDbForColumn(col) != null)
                        {
                            object val = row[col];
                            if (val is Boolean)
                            {
                                val = ((bool)val)?1:0;
                            }
                            if (val is CDateTimeEx && val != null)
                            {
                                val = ((CDateTimeEx)val).DateTimeValue;
                            }
                            OleDbParameter param = command.Parameters.Add("@" + nParam.ToString(), COleDbTypeConvertor.GetTypeOleDbFromType(col.DataType));
                            param.Value = val;
                            nParam++;
                        }
                    }
                    command.ExecuteNonQuery();
                }

/*
 *
 *
 *                              OleDbDataAdapter adapter = new OleDbDataAdapter ("select * from "+table.TableName, m_connection );
 *                              OleDbCommandBuilder builder = new OleDbCommandBuilder ( adapter );
 *                              adapter.InsertCommand = builder.GetInsertCommand();
 *                              adapter.InsertCommand.Transaction = m_transaction;
 *                              DataTable tableDest = table.Clone();
 *                              foreach ( DataRow row in table.Rows )
 *                              {
 *                                      DataRow newRow = tableDest.NewRow();
 *                                      newRow.ItemArray = row.ItemArray;
 *                                      tableDest.Rows.Add ( newRow );
 *                              }
 *                              adapter.Update ( tableDest );*/
            }
            catch (Exception e)
            {
                result.EmpileErreur(new CErreurException(e));
                result.EmpileErreur(I.T("Table creation error @1|169", table.TableName));
            }
            return(result);
        }