Click here to Skip to main content
15,917,473 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
try
            {
                SqlCommand cmd = new SqlCommand("select * from buy where numero='" + comboBox1.Text + "'", con);
                con.Close();
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                if (rdr.Read())
                {
                    DateTime date = System.Convert.ToDateTime(dateTimePicker1.Text);   
                    date=rdr[0].ToString();
                    txtPrtNo.Text = rdr[1].ToString();
                    txtCliNo.Text = rdr[2].ToString();
                    txtQty.Text = rdr[3].ToString();
                    txtUprice.Text = rdr[4].ToString();
                    txtTax.Text = rdr[5].ToString();
                    txtTotP.Text = rdr[6].ToString();
                    txtBalnc.Text = rdr[7].ToString();
                    txtAmtpd.Text = rdr[8].ToString();
                    
                }
                con.Close();
            }
            catch (Exception mn)
            {
                MessageBox.Show(mn.Message);
            }
Posted
Updated 5-Aug-12 6:58am
v2
Comments
Kenneth Haugland 5-Aug-12 13:00pm    
Whats wrong with the answers you got here:
http://www.codeproject.com/Questions/434810/my-comboBox-do-not-show-the-date-it-gives-me-this

You should normally not re-post a question. Use the Improve Question instead if you didnt get a good reply :)

Java
date=rdr[0].ToString();

this line is wrong, you cannot implicitly convert a string to a DateTime - as the message clearly tells you.
 
Share this answer
 
In the code u posted u have once set the date variable from some datepicker and in the very next line u are trying to overwrite the date's value with SqlDataReader rdr data. I mean that's a bit useless thing to do. First of all u decide what data u want to store in date variable and then try the following..

C#
Convert.ToDateTime(rdr[0].ToString())
or
C#
DateTime.Parse(rdr[0].ToString());
 
Share this answer
 
v2
Comments
Gilbertinino 5-Aug-12 14:11pm    
i replaced the line of code with 'Convert.ToDateTime(rdr[0].ToString())' and when i try to debugg again it gives this error 'String was not recognized as a valid DateTime.'
Prabhat Spark 6-Aug-12 0:51am    
That means only one thing that the format of the data at 0 index of the table contains date in an invalid format. Can u copy a sample row and post it here so that I can see what's causing the error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900