hello,
I am saving some data in sql of type datetime but the value I am getting is 1900-01-02 00:00:00.000 what must I do?

The problem was that I was not adding the current time. but another problem arose when I am trying to querry these results the reader is not reading any result.here is my code:

 SqlConnection s = new SqlConnection(con);
            s.Open();
            SqlCommand com = new SqlCommand("SELECT * FROM t_Image WHERE Image_ID= @x",s);

            SqlParameter p = new SqlParameter();
            p.ParameterName = "@x";
            p.Value = listView1.SelectedItems[0].Text;
            com.Parameters.Add(p);

            reader = com.ExecuteReader();

            while (reader.Read())
            {
                byte[] data = (byte[])reader[1];
                Image image = Image.FromStream(new System.IO.MemoryStream(data));
                pictureBox1.Image = image;

            }
            reader.Close();

any solution?

Hi,
So now you salve the issue about Datetime?
-- --
Abour your last issue, not reading data.
Does the code go into while loop? (hint: put a break point and go line by line, this way you can check whats really going on).
And I would now use a while loop, if you only wanna show an image, better use if loop. Else you will always get shown the very last image regarding the select query (and its where clause).

the whole problem is about datetime parameter I am passing to database querry its of the format 6/9/2012....
but the sql saves the datetime as 6-9-2012 so how to convert my parameter into the desired format

but the sql saves the datetime as 6-9-2012 so how to convert my parameter into the desired format

No it doesn't save it in that format, it displays it in that format. Internally SQL Server is saving the date/time as a very large number representing seconds since the epoch date. Don't worry about how SQL Server stores things like this.

Parse the selected item into a DateTime object, then set the parameter using that (and tell it it's a datetime parameter).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.