D
djamila
Hi,
I have one problem with VB.Net using Access database that I couldn't
find the solution.
I have a form that represents a task with two buttons: the button
start which we click first to start the task and it will be disabled
just after that. And the button finish which will be enabled when we
click the start button and it represents the end of the task. After
that the two buttons will be disabled.
I use two fields in ma access table: start and finish of type date.
In my program I select the values of start and finish. If start is
null I enable start button and disable finish button. If start is not
null and finish is null I disable the start button and enable the
finish button. In the case that the two values exist, I disable the
two buttons.
So in my form load I have the following program:
Try
objetconnection = New
System.Data.OleDb.OleDbConnection(sconnection)
sql_text = "Select start, finish from User_Project_Task
where login like '" & Variables.login & _
"' and Project_ID = " & Project_ID & " and task_ID = " & Task_Id
Command = New OleDbCommand(sql_text, objetconnection)
objetconnection.Open()
reader = Command.ExecuteReader
If reader.HasRows Then
reader.Read()
start = reader.GetDateTime(0)
finish = reader.GetDateTime(1)
If start <> Nothing Then
If finish <> Nothing Then
bt_finish.Enabled = False
Else
bt_finish.Enabled = True
End If
bt_start.Enabled = False
Else
bt_start.Enabled = True
bt_finish.Enabled = True
End If
End If
reader.Close()
objetconnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
When I run my program And I have a date value in start field and a
null value in finish field the program gives the following error for
the finish = reader.GetDateTime(1) -> The cast specified is not valid.
So the value is null and can not be read as GetDateTime. So how can I
test the value if I couldn't read it in a variable.
Please, can any one help me for that.
Best regards,
Djamila.
I have one problem with VB.Net using Access database that I couldn't
find the solution.
I have a form that represents a task with two buttons: the button
start which we click first to start the task and it will be disabled
just after that. And the button finish which will be enabled when we
click the start button and it represents the end of the task. After
that the two buttons will be disabled.
I use two fields in ma access table: start and finish of type date.
In my program I select the values of start and finish. If start is
null I enable start button and disable finish button. If start is not
null and finish is null I disable the start button and enable the
finish button. In the case that the two values exist, I disable the
two buttons.
So in my form load I have the following program:
Try
objetconnection = New
System.Data.OleDb.OleDbConnection(sconnection)
sql_text = "Select start, finish from User_Project_Task
where login like '" & Variables.login & _
"' and Project_ID = " & Project_ID & " and task_ID = " & Task_Id
Command = New OleDbCommand(sql_text, objetconnection)
objetconnection.Open()
reader = Command.ExecuteReader
If reader.HasRows Then
reader.Read()
start = reader.GetDateTime(0)
finish = reader.GetDateTime(1)
If start <> Nothing Then
If finish <> Nothing Then
bt_finish.Enabled = False
Else
bt_finish.Enabled = True
End If
bt_start.Enabled = False
Else
bt_start.Enabled = True
bt_finish.Enabled = True
End If
End If
reader.Close()
objetconnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
When I run my program And I have a date value in start field and a
null value in finish field the program gives the following error for
the finish = reader.GetDateTime(1) -> The cast specified is not valid.
So the value is null and can not be read as GetDateTime. So how can I
test the value if I couldn't read it in a variable.
Please, can any one help me for that.
Best regards,
Djamila.