here's my code
con.Open();
SqlCommand cmd = new SqlCommand("SELECT [Date] FROM [dbo].[DS_PROJECT] ORDER BY Date ASC", con);
cmd.ExecuteNonQuery();
SqlCommand cm = new SqlCommand("SELECT [Time] FROM [dbo].[DS_PROJECT] ORDER BY Time ASC", con);
cm.ExecuteNonQuery();
con.Close();
DateTime currenttime = DateTime.Now;
DateTime userdate = Convert.ToDateTime(cmd);
DateTime usertime = Convert.ToDateTime(cm);
i want to convert the date and time values saved in my database but am unable to do it and this exception occurs
Unable to cast object of type 'System.Data.SqlClient.SqlCommand' to type 'System.IConvertible
Please Help me. Thank You
ExecuteNonQueryshould be used for SQL commands that modify data (e.g. Inserts, Updates, Deletes). If you want to read data you should useExecuteReaderinstead. See msdn.microsoft.com/en-us/library/9kcbe65k(v=vs.110).aspxExecuteReadermethod of aSqlCommandand take data from the data reader it returns. There is a simple example on this page.ExecuteScalarmethod, see msdn.microsoft.com/en-us/library/…