Click here to Skip to main content
15,890,345 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
am developing an application but am getting exception as conversion from type Date to Double is not valid.
VB
while (reader.Read())

                        myarrlst11_1.Add(reader("sno").ToString)    'sno

                        a = reader("Date")
                        b = reader("Time")
                        a = Convert.ToInt32(reader(Convert.ToInt32(a)))
                        b = Convert.ToInt32(reader(Convert.ToInt32(b)))
                        StrSql.Parameters.AddWithValue("@a", Convert.ToDouble(a))
                        StrSql.Parameters.AddWithValue("@b", Convert.ToDouble(b))

end while

plz help me with sample code or any idea why this exception is coming
Posted
Updated 2-Jul-12 0:03am
v2
Comments
Shemeer NS 2-Jul-12 6:10am    
can you explain what you are tring to acheive?
Member 8953292 2-Jul-12 6:16am    
actually i want to take a excel sheet with data as input and using excel sheet values i want to draw a chart.am able to display that excel sheet but in that sheet i have date and time to display on chart so i am trying to do that but am getting many exceptions as above and input string not in a correct format and Unable to cast object of type 'System.DateTime' to type 'System.DateTime[]'.so i want u or any one can help me complete this application plz

1 solution

VB
a = reader("Date")
b = reader("Time")
a = Convert.ToInt32(reader(Convert.ToInt32(a)))
b = Convert.ToInt32(reader(Convert.ToInt32(b)))
StrSql.Parameters.AddWithValue("@a", Convert.ToDouble(a))
StrSql.Parameters.AddWithValue("@b", Convert.ToDouble(b))


All throughout the above code, you are trying to convert extracted values of a & b

Based on the field names (& error you get), it looks like values of a & b are of DateTime type. Since the data extracted is of Date type, you get an error when you try to convert it into double.

Options:
1. Get the data in format you want.
2. change your strSql that expects double, pass dates to it and modify it to accept dates instead of double.
 
Share this answer
 
Comments
Sebastian T Xavier 2-Jul-12 6:36am    
Correct observation. My 5+
Member 8953292 2-Jul-12 6:39am    
plz give am example how to do that
Sandeep Mewara 2-Jul-12 7:26am    
Whats in there to give an example? :doh:
Sebastian T Xavier 2-Jul-12 7:32am    
This question itself is an example.....

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

  Print Answers RSS


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