Click here to Skip to main content
15,887,344 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
If reader("Time").ToString <> "" And reader("DeviceId").ToString() <> "" Then

                            myarrlst11_1.Add(reader("sno").ToString)    'sno
                            data_time = reader("Time").ToString.Split(":")
                            myarrlst13_1.Add(reader("DeviceId").ToString)   'Device id


                            myarrlst21_1.Add(data_time(0))
                            myarrlst22_1.Add(data_time(1))
                            myarrlst23_1.Add(data_time(2))
                            Try
                                time1 = Convert.ToInt32(data_time(0) & data_time(1) & data_time(2))

'THIS IS THE LINE WHERE IT IS SHOWING AS INPUT STRING NOT IN A CORRECT FORMAT

                            Catch ex As Exception

                            End Try
                            myarlst_tm_1.Add(time1)
Posted
Updated 3-Jul-12 20:24pm
v2
Comments
Sebastian T Xavier 4-Jul-12 2:26am    
This is not a good question. Use improve question to make it clear,and please don't use CAPS.

1 solution

Hi,

Whats the type of the variable time1. you are trying to assign an integer type value to time1. Please check the value of
C#
data_time(0) & data_time(1) & data_time(2)
before casting it to integer.

Regards
Sebastian
 
Share this answer
 
Comments
Member 8953292 4-Jul-12 2:32am    
time is of type double.
i want to convert the data in data_time(0)&data_time(1)&data_time(2) into double so that it can support drawing charts.
the code is..
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim a1, a2, a3, b As String
a1 = ""
a2 = ""
a3 = ""
b = ""

Dim data_time(3) As String
Dim data_date(3) As String
Dim time1 As Double


connString = "Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=C:\Users\SoftwareDeveloper\Desktop\value1.xls;" & "Extended Properties=""Excel 12.0;HRD=Yes;"";"

Dim excelConnection As OleDb.OleDbConnection = New OleDb.OleDbConnection(connString)
excelConnection.ConnectionString = connString

Using excelConnection
excelConnection.Open()

Dim StrSql As OleDbCommand = New OleDbCommand("")
Dim reader As OleDbDataReader
Dim date1 As OleDbCommand = New OleDbCommand("")

StrSql.Connection = excelConnection


StrSql.CommandText = "select sno,Time,DeviceId from [value$]"
reader = StrSql.ExecuteReader()

date1.Connection = excelConnection
StrSql.Connection = excelConnection

Try
While (reader.Read())
If reader("Time").ToString <> "" And reader("DeviceId").ToString() <> "" Then

myarrlst11_1.Add(reader("sno").ToString) 'sno
data_time = reader("Time").ToString.Split(":")
myarrlst13_1.Add(reader("DeviceId").ToString) 'Device id


myarrlst21_1.Add(data_time(0))
myarrlst22_1.Add(data_time(1))
myarrlst23_1.Add(data_time(2))
Try
time1 = Convert.ToInt32(data_time(0) & data_time(1) & data_time(2))

Catch ex As Exception

End Try
myarlst_tm_1.Add(time1)


End If
End While


' End If
Catch ex As Exception

End Try

reader.Close()
excelConnection.Close()





FormatChart()
AutoFormatChart()
End Using
Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Column
Chart1.Series(Chart1.Series.Count - 1).Points.DataBindXY(myarrlst13_1, myarrlst21_1)
Chart1.Series(Chart1.Series.Count - 1).Color = Color.Red
Catch ex As Exception

End Try
End Sub

this is code and at time1 = Convert.ToInt32(data_time(0) & data_time(1) & data_time(2)) am getting exception

plz help
Sebastian T Xavier 4-Jul-12 2:34am    
try
Convert.ToDouble(data_time(0) & data_time(1) & data_time(2))
Member 8953292 4-Jul-12 2:36am    
i used it but still it is showing input string not in a correct format
Sebastian T Xavier 4-Jul-12 2:47am    
what is the output of
data_time(0) & data_time(1) & data_time(2)
Member 8953292 4-Jul-12 3:01am    
for data_time(0) is "12/30/1899 3"
data_time(0) is 29
data_time(1) is 28PM
but while converting it to double it is giving exception

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