473,609 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can i compare current date with the date stored in sql server Table in VB?

3 New Member
Hello Everyone please help me. I am new to VB and i want to know how to compare the current date with the date stored in the database table?
Jun 26 '14 #1
4 1645
twinnyfo
3,653 Recognized Expert Moderator Specialist
Jayasai,

You need to provide more information for us to help you. Have you tried anything, yet? What types of errors are you getting? We would love to trouble shoot, but we don't have anything to go by.
Jun 26 '14 #2
Jayasai
3 New Member
Expand|Select|Wrap|Line Numbers
  1. Dim date1 As Date
  2.         Dim DOB As Date
  3.         Dim sql1 As String
  4.  
  5.         sql1 = "select DATE_OF_BIRTH from PERSON1 where  PERSON_ID=person.personId"
  6.         Dim command As OracleCommand = New OracleCommand(sql1)
  7.         'Dim datareader As OracleDataReader = command.ExecuteReader()
  8.         date1 = Convert.ToDateTime(Today)
  9.         DOB = command.ExecuteScalar()
  10.         If Date.Compare(date1, DOB) = 0 Then
  11.             Dim message As String = "!**Greetings***! Wow Today is Your's Birthday. Wish You A Happy Birthday! Wish you many more returns of the day. Have a lovely day"
  12.             Dim sb As New System.Text.StringBuilder()
  13.             sb.Append("<script type='text/javascript'>")
  14.             sb.Append("window.onload=function(){")
  15.             sb.Append("alert('")
  16.             sb.Append(message)
  17.             sb.Append(" ')};")
  18.             sb.Append("</script>")
  19.             ClientScript.RegisterClientScriptBlock(Me.GetType(), "alert", sb.ToString())
  20.         Else
  21.             Dim username As String
  22.             Dim sql2 As String
  23.             sql2 = "select First_Name from PERSON1 where convert.GETDATE()=DATE_OF_BIRTH "
  24.             Dim command1 As OracleCommand = New OracleCommand(sql2)
  25.             'Dim datareader As OracleDataReader = command.ExecuteReader()
  26.             username = command.ExecuteScalar()
  27.             Dim message1 As String = "!**Greetings***! Wow Today is " + username + " Birthday  and Wish him/her a Happy Birthday!"
  28.             Dim sb As New System.Text.StringBuilder()
  29.             sb.Append("<script type='text/javascript'>")
  30.             sb.Append("window.onload=function(){")
  31.             sb.Append("alert('")
  32.             sb.Append(message1)
  33.             sb.Append(" ')};")
  34.             sb.Append("</script>")
  35.             ClientScript.RegisterClientScriptBlock(Me.GetType(), "ClientScript", "alert", sb.ToString())
  36.         End If
  37. I tried this code and i am getting error like this
  38.  
  39.  
  40.  Invalid operation. The connection is closed.
  41. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
  42.  
  43. Exception Details: System.InvalidOperationException: Invalid operation. The connection is closed.
  44.  
  45. Source Error:
  46.  
  47.  
  48. Line 22:         'Dim datareader As OracleDataReader = command.ExecuteReader()
  49. Line 23:         date1 = Convert.ToDateTime(Today)
  50. Line 24:         DOB = command.ExecuteScalar()
  51. Line 25:         If Date.Compare(date1, DOB) = 0 Then
  52. Line 26:             Dim message As String = "!**Greetings***! Wow Today is Your's Birthday. Wish You A Happy Birthday! Wish you many more returns of the day. Have a lovely day"
Jun 27 '14 #3
Jayasai
3 New Member
twinnyfo,

Thank u for your response
Jun 27 '14 #4
twinnyfo
3,653 Recognized Expert Moderator Specialist
Have you stepped through the code and validated that the connection is still open and that all variables evaluate to what you think they ought to be?
Jun 28 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
5120
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows for each record, each row accounts for a different type of outcome I'm having trouble with MySQL date comparison. I'm looking for some kind of query that will compare the all date column and only give me the latest date. Then once I have it, ...
6
8377
by: Phil Powell | last post by:
The date field I believe is of type datetime, but I'm sorry I have absolutely no idea how to put today's date into a datetime column using ASP and SQL Server. Folks, I'm a LINUX guy!!! This is a project I have to get done today and that is about the only thing snagging it from being done before COB today. Please help.
7
60502
by: Vinnie Davidson | last post by:
Hello! I'm trying to get all records from my SQL Server Database with "DeadlineDate" = today (not today - 24 hours). All records has a field called "DeadlineDate", and the date is stored in this field like this: 13.08.2005 07:00:00 I dont care about the hours (Ex: 07:00:00), just the date (ex: 13.08.2005). This is the SQL I have made, it gets all the record with the date = today -
0
2427
by: Mark | last post by:
All, Excuse the re-post but I have found something which works for the UserID but not for the Password (see previous post below). The problem is I don't understand how it works and therefore cannot update it to do as I need. Could someone explain A) how to modify this to make sure the username & password are valid or B) How the below works so I can do it myself. I have never seen "PARAMETERS" used before in SQL which has thrown me...
3
3653
by: | last post by:
I have a datetime field in table. I want to insert the current time of database server to the table thr ASP.NET (C#). I have dataset to do the insert: DataSet1.TableNameRow rowNew = (DataSet1.TableNameRow)DataSet1.TableName.NewRow(); rowNew.DateTimeField = System.DateTime.Now;
7
23054
by: joeyej | last post by:
How do I compare today's date with this string (in my inc file) so that I can set an alert if date choice i.e. May 15, 2006 not at least greater than two days from current date? <option value="May 15, 2006, (Monday), 10am">May 15, 2006, (Monday), 10am Thanks, Joe
0
1621
by: sourabhmca | last post by:
hi friend, I am want to insert date with time into sql server2000 using JSP.I hv 3 combo box for dd mm yyyy and 2 text box for hh and min ? and my table field type is smalldatetime.after that i want compare 2 date and want time in hh and min and display diff time and both date on sql server ? plz help soon?
0
1224
by: comp21 | last post by:
Hi, Now, I have retrieved or imported data from excel spreadsheet to vb6 application. Now I want to compare this part of data with the one already existing in mssql2000 server(table name being same). If some data which is there in excel spread sheet not to be found in mssql2000 server then those data has to be stored in a seperate table in mssql server. Can anyone please help me with the code....
1
2034
parshupooja
by: parshupooja | last post by:
Hi , I have asp.net page. I have few fields on page , I am inserting value into this fields which are getting saved into SQL server database. I have additional column into the table(SQL Server) named UserId. along with these field values on the page I want to insert Userid into the Userid olumn. I have Login page where User inserts Userid and Password. Some suggested to user session variables for that. I don't know anything about...
7
12060
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
0
8138
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8090
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8578
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8554
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8229
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8408
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7021
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.