problem with date

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2007
Posts: 4
Reputation: usershan is an unknown quantity at this point 
Solved Threads: 0
usershan usershan is offline Offline
Newbie Poster

problem with date

 
0
  #1
May 16th, 2007
Hi all,

I am trying to insert date but not able to, im using SQL server.

This is my code:
Dim str As String
Dim cmd As SqlCommand
Dim con As SqlConnection
Dim sql As String

Function AccessDate(ByVal dateandtime)
Dim myday
Dim mymonth
Dim myyear

myday = Day(dateandtime)
If Len(myday) = 1 Then myday = "0" & myday

mymonth = Month(dateandtime)
If Len(mymonth) = 1 Then mymonth = "0" & mymonth

myyear = Year(dateandtime)
AccessDate = myyear & "-" & mymonth & "-" & myday

End Function


Protected Sub btnadd_Click(ByVal sender As Object, ByVal e As System.EventArgs)
sql = "insert into cashtable(tdate) values(# " & AccessDate(Now()) & " # )"

Try
con = New SqlConnection(str)
cmd = New SqlCommand(sql, con)
con.Open()
cmd.ExecuteNonQuery()
lblinfo.Visible = True
lblinfo.Text = "Record Inserted"

Catch ex As Exception
lblinfo.Visible = True
lblinfo.Text = ex.Message
Finally
con.Close()
End Try

End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

str = ConfigurationManager.ConnectionStrings("ShanthiConnectionString").ConnectionString
lblinfo.Visible = False
GridView1.Visible = False

End Sub



Thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 216
Reputation: jamello is an unknown quantity at this point 
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

Re: problem with date

 
0
  #2
May 21st, 2007
Originally Posted by usershan View Post
Hi all,

I am trying to insert date but not able to, im using SQL server.

This is my code:
Dim str As String
Dim cmd As SqlCommand
Dim con As SqlConnection
Dim sql As String

Function AccessDate(ByVal dateandtime)
Dim myday
Dim mymonth
Dim myyear

myday = Day(dateandtime)
If Len(myday) = 1 Then myday = "0" & myday

mymonth = Month(dateandtime)
If Len(mymonth) = 1 Then mymonth = "0" & mymonth

myyear = Year(dateandtime)
AccessDate = myyear & "-" & mymonth & "-" & myday

End Function


Protected Sub btnadd_Click(ByVal sender As Object, ByVal e As System.EventArgs)
sql = "insert into cashtable(tdate) values(# " & AccessDate(Now()) & " # )"

Try
con = New SqlConnection(str)
cmd = New SqlCommand(sql, con)
con.Open()
cmd.ExecuteNonQuery()
lblinfo.Visible = True
lblinfo.Text = "Record Inserted"

Catch ex As Exception
lblinfo.Visible = True
lblinfo.Text = ex.Message
Finally
con.Close()
End Try

End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

str = ConfigurationManager.ConnectionStrings("ShanthiConnectionString").ConnectionString
lblinfo.Visible = False
GridView1.Visible = False

End Sub



Thanks in advance
 
Try replacing the '#' with one inverted comma like so '
sql = "insert into cashtable(tdate) values(' " & AccessDate(Now()) & " ' )"
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC