473,385 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Access and VB.Net

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.

Mar 5 '07 #1
2 1433
Djamila,

Can you set in top of your program.

Option Strict On

In design time you will than be warned for some errors.

Cor

"djamila" <dj***********@gmail.comschreef in bericht
news:11**********************@v33g2000cwv.googlegr oups.com...
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.

Mar 5 '07 #2
Are you sure that the first and second columns of your table are date/time
fields AND RE NOT NULL? What if you get those as strings and then look at
them before doing something with them? Then does your code work?

Robin S.
------------------------------------------
"djamila" <dj***********@gmail.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
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.

Mar 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

63
by: Jerome | last post by:
Hi, I'm a bit confused ... when would I rather write an database application using MS Access and Visual Basic and when (and why) would I rather write it using Visual Studio .Net? Is it as easy...
13
by: bill | last post by:
I am trying to convince a client that dotNet is preferable to an Access project (ADP/ADE). This client currently has a large, pure Access MDB solution with 30+ users, which needs to be upgraded....
1
by: Dave | last post by:
Hello NG, Regarding access-declarations and member using-declarations as used to change the access level of an inherited base member... Two things need to be considered when determining an...
13
by: Simon Bailey | last post by:
I am a newcomer to databases and am not sure which DBMS to use. I have a very simplified knowledge of databases overall. I would very much appreciate a (simplifed) message explaining the advantages...
0
by: Frederick Noronha \(FN\) | last post by:
---------- Forwarded message ---------- Solutions to Everyday User Interface and Programming Problems O'Reilly Releases "Access Cookbook, Second Edition" Sebastopol, CA--Neither reference book...
20
by: Olav.NET | last post by:
I am a .NET/C++ developer who is supposed to do some work with Access. I do not know much about it except for the DB part. Questions: *1* I am looking for INTENSIVE books to get quickly up to...
64
by: John | last post by:
Hi What future does access have after the release of vs 2005/sql 2005? MS doesn't seem to have done anything major with access lately and presumably hoping that everyone migrates to vs/sql. ...
1
by: com | last post by:
Extreme Web Reports 2005 - Soft30.com The wizard scans the specified MS Access database and records information such as report names, parameters and subqueries. ......
17
by: Mell via AccessMonster.com | last post by:
Is there a way to find out where an application was created from? i.e. - work or home i.e. - if application sits on a (work) server/network, the IT people know the application is sitting...
37
by: jasmith | last post by:
How will Access fair in a year? Two years? .... The new version of Access seems to service non programmers as a wizard interface to quickly create databases via a fancy wizard. Furthermore, why...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.