Archive for the ‘Développement’ Category

Lorsqu’on récupère Backup base SQL Server: impossible de générer Diagram

Mardi, mai 18th, 2010

Souvent quand on récupère une base à partir d’un Backup SQL Server, on a le message suivant lorsqu’on veut générer un diagram de la base (SQL Server Management Studio): (Lire la suite…)

Tuer une liste de processus mysql

Mardi, février 2nd, 2010

$result = mysql_query(« SHOW FULL PROCESSLIST »);
while ($row=mysql_fetch_array($result)) {
$process_id=$row["Id"];
if ($row["Time"] > 200 ) {
$sql= »KILL $process_id »;
mysql_query($sql);
}
}

Truncate all sur les tables d’une base SqlServer 2005

Mercredi, décembre 30th, 2009

Ce script permet de vider les tables d’une base Sql Server. L’intérêt est de pouvoir faire des tests pour un import de données par exemple sans être obligé de créer une base où les tables sont vides à chaque fois (Lire la suite…)

Faire pivoter un dataset

Mercredi, décembre 23rd, 2009
private void BindData()
{
    DataSet ds = this.GetDetail(); // Some DataSet

    DataSet new_ds = FlipDataSet(ds); // Flip the DataSet

    DataView my_DataView = new_ds.Tables[0].DefaultView;
    this.my_DataGrid.DataSource = my_DataView;
    this.my_DataGrid.DataBind();
}

public DataSet FlipDataSet(DataSet my_DataSet)
{
    DataSet ds = new DataSet();
    foreach(DataTable dt in my_DataSet.Tables)
    {
        DataTable table = new DataTable();
        for(int i=0; i<=dt.Rows.Count; i++)
        {
            table.Columns.Add(Convert.ToString(i));
        }
        DataRow r;
        for(int k=0; k<dt.Columns.Count; k++)
        {
            r = table.NewRow();
            r[0] = dt.Columns[k].ToString();
            for(int j=1; j<=dt.Rows.Count; j++)
                r[j] = dt.Rows[j-1][k];
        }
        table.Rows.Add(r);
    }
    ds.Tables.Add(table);
}
return ds;
}

http://www.codeproject.com/KB/database/Vertical_rows_in_Datagrid.aspx

PIVOT

Vendredi, décembre 11th, 2009

public static DataSet convertDataReaderToDataSet(DbDataReader reader)

{

DataSet dataSet = new DataSet();

do

{

// Create new data table

DataTable schemaTable = reader.GetSchemaTable();

DataTable dataTable = new DataTable();

if (schemaTable != null)

{

// A query returning records was executed

for (int i = 0; i < schemaTable.Rows.Count; i++)

{

DataRow dataRow = schemaTable.Rows[i];

// Create a column name that is unique in the data table

string columnName = (string)dataRow["ColumnName"]; //+ « <C » + i + « /> »;

// Add the column definition to the data table

DataColumn column = new DataColumn(columnName, (Type)dataRow["DataType"]);

dataTable.Columns.Add(column);

}

dataSet.Tables.Add(dataTable);

// Fill the data table we just created

while (reader.Read())

{

DataRow dataRow = dataTable.NewRow();

for (int i = 0; i < reader.FieldCount; i++)

dataRow[i] = reader.GetValue(i);

dataTable.Rows.Add(dataRow);

}

}

else

{

// No records were returned

DataColumn column = new DataColumn(« RowsAffected »);

dataTable.Columns.Add(column);

dataSet.Tables.Add(dataTable);

DataRow dataRow = dataTable.NewRow();

dataRow[0] = reader.RecordsAffected;

dataTable.Rows.Add(dataRow);

}

}

while (reader.NextResult());

return dataSet;

}

Pour Info

public List<T_METHODOLOGIES> GetT_METHODOLOGIESsDEP()

{

try

{

List<T_METHODOLOGIES> lstT_METHODOLOGIESs = new List<T_METHODOLOGIES>();

DbCommand oDbCommand = DbProviderHelper.CreateCommand(@ »DECLARE @query VARCHAR(4000) DECLARE @metho VARCHAR(2000) SELECT     @metho = STUFF

((SELECT DISTINCT ‘],[' + METHODOLOGIE

FROM         T_METHODOLOGIES

ORDER BY '],[' + METHODOLOGIE FOR XML PATH('')), 1, 2, '') + ']‘

SET              @query = ‘SELECT * FROM

(

SELECT     T_DEPARTEMENTS.NOM AS DEPARTEMENT, T_REPARTITION.REPARTITION, T_METHODOLOGIES.METHODOLOGIE, YEAR(T_ETUDES.DATE) AS DATE

FROM         T_REPARTITION INNER JOIN

T_ETUDES ON T_REPARTITION.ID_ETUDE = T_ETUDES.ID INNER JOIN

T_METHODOLOGIES ON T_ETUDES.ID_METHODOLOGIE = T_METHODOLOGIES.ID INNER JOIN

T_DEPARTEMENTS ON T_REPARTITION.ID_DEPARTEMENT = T_DEPARTEMENTS.ID

)t

PIVOT (SUM(REPARTITION) FOR METHODOLOGIE

IN (‘

+ @metho + ‘)) AS pvt’ EXECUTE (@query) », CommandType.Text);

DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);

convertDataReaderToDataSet(oDbDataReader);

}

Excel à partir d’un GridView

Mardi, novembre 24th, 2009

Génération simple de document Excel à partir d’un Gridview (Lire la suite…)

Common Domain Logic Patterns

Jeudi, octobre 1st, 2009

Using common domain logic patterns in your .NET applications ou comment les application vont interagir avec les données

http://articles.techrepublic.com.com/5100-10878_11-5107664.html

gestion des exceptions dans Global.asax

Jeudi, octobre 1st, 2009

 

void Application_Error(object sender, EventArgs e)
{
   //get reference to the source of the exception chain
   Exception ex = Server.GetLastError().GetBaseException();

   //log the details of the exception and page state to the
   //Windows 2000 Event Log
   EventLog.WriteEntry(« Test Web »,
     « MESSAGE:  » + ex.Message +
     « \nSOURCE:  » + ex.Source +
     « \nFORM:  » + Request.Form.ToString() +
     « \nQUERYSTRING:  » + Request.QueryString.ToString() +
     « \nTARGETSITE:  » + ex.TargetSite +
     « \nSTACKTRACE:  » + ex.StackTrace,
     EventLogEntryType.Error);

   //Insert optional email notification here…
}

src
http://www.developer.com/net/asp/article.php/961301/Global-Exception-Handling-with-ASPNET.htm

Appeler une méthode serveur à partir d’un javascript

Jeudi, juillet 2nd, 2009

J’ai trouvé ce message intéressant sur developpez.net

-Créer une méthode static dans le code behind (c’est la méthode qui sera appelée dans le javascript) (Lire la suite…)

Transformer une Collection List générique en dataset List2DataSet

Mercredi, juin 10th, 2009

Le but est de transformer une liste d’élément en Dataset.

Dans cet exemple je transforme une liste de comptes en DS. (Lire la suite…)