Problème d'affichage de date
Bonjour,
J'ai fait un code me permettant à partir d'un controle FileUpload d'insérer un fichier dans une base de données. J'ai ajouté l'ajout de quelques champs à celui-ci : le nom du fichier, sa taille et la date d'insertion.
J'ai alors un drôle de problème avec la date. J'ai testé différents format de date (Date.now.ToString - Date.now.ToShortDateString - etc) mais j'obtiens à chaque fois le même résultat : 01/07/2010 00:00:00.
Je vous met mon code au cas quelqu'un saurait d'où cela pourrait venir :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| protected void BoutonAjouterfichier_Click(object sender, ImageClickEventArgs e)
{
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()))
{
if (FileUpload1.HasFile)
{
if (FileUpload1.PostedFile.ContentLength < 17179869)
{
try
{
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandText = "INSERT INTO TableImage(Image,Chemin,Taille,DateCreation) values (@file_bytes,@Chemin,@Taille,@DateCreation)";
command.Parameters.Add("file_bytes", SqlDbType.Image).Value = FileUpload1.FileBytes;
command.Parameters.Add("Chemin", SqlDbType.VarChar, 50).Value = FileUpload1.FileName;
command.Parameters.Add("Taille", SqlDbType.VarChar, 50).Value = FileUpload1.PostedFile.ContentLength +" "+ "kb";
command.Parameters.Add("DateCreation", SqlDbType.Date).Value = DateTime.Now.ToShortDateString();
command.ExecuteNonQuery();
}
}
catch (Exception err)
{
Label1.Text = "ERREUR: " + err.Message.ToString();
}
finally
{
try
{
//Mise à jour du tableau
GridViewListeFichier.DataBind();
//Fermeture de la connexion
connection.Close();
}
catch (Exception err2)
{
Trace.Write(err2.Message);
}
}
}
else
{
Label1.Text = "Fichier trop volumineux! ";
}
}
else
{
Label1.Text = "Vous n'avez pas spécifié de fichier! ";
}
}
} |
Merci.