1 pièce(s) jointe(s)
afficher datetimepicker a partir d'une donnée SQL
Bonjour voici mon probleme, je suis entrain de monter un petit programme en c#.
voici mon erreur
Citation:
Unable to cast object of type 'System.DateTime' to type 'System.String'.
j'aurrais besoin d'afficher la date de naissance ainsi que la date d'entrer a partir de ID de la personne qui se trouve dans une BD SQL Dans leur datetimepicker.
J'arrive a afficher les autres champ sans probleme mais pour ces deux la....
voici mon code
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
|
private void btAFFICHE_Click(object sender, EventArgs e)
{
String @ID = txtDOSSIER.Text;
String @NOM = txtNOM.Text;
String @PRENOM = txtPRENOM.Text;
String @NAISSANCE = dtNAISSANCE.Text;
String @ENTRER = dtENTRER.Text;
SqlConnection cs = new SqlConnection("Data Source=SRV-SQL; Initial Catalog=DB_RENASCI; Integrated Security=TRUE");
cs.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cs;
cmd.Parameters.AddWithValue("@ID", ID);
cmd.CommandText = "select NOM from ENTRER WHERE ID=@ID";
txtNOM.Text = (string)cmd.ExecuteScalar();
SqlCommand cmd1 = new SqlCommand();
cmd.Connection = cs;
cmd.CommandText = "select PRENOM from ENTRER WHERE ID=@ID";
txtPRENOM.Text = (string)cmd.ExecuteScalar();
SqlCommand cmd2 = new SqlCommand();
cmd.Connection = cs;
cmd.CommandText = "select NOM from ENTRER WHERE ID=@ID";
txtNOM.Text = (string)cmd.ExecuteScalar();
SqlCommand cmd3 = new SqlCommand();
cmd.Connection = cs;
cmd.CommandText = "select ENTRER from ENTRER WHERE ID=@ID";
dtENTRER.Text = (string)cmd.ExecuteScalar();
SqlCommand cmd4 = new SqlCommand();
cmd.Connection = cs;
cmd.CommandText = "select NAISSANCE from ENTRER WHERE ID=@ID";
dtNAISSANCE.Text = (string)cmd.ExecuteScalar();
cs.Close(); |
merci a l'avance pour votre aide precieuse