| | |
problem with date
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2007
Posts: 4
Reputation:
Solved Threads: 0
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
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
•
•
•
•
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()) & " ' )"
![]() |
Similar Threads
- slow network browsing to shares (Windows NT / 2000 / XP)
- date problem (Visual Basic 4 / 5 / 6)
- linked list problem!!! (C)
- date-time problem (C++)
- Need to change the Email received date!!!! (Web Browsers)
- Dreamweaver MX2004 & date problem, etc. (Graphics and Multimedia)
- Issue related to combobox.... (VB.NET)
- date time issue in JSP (JSP)
- Is "NPFMONTR.exe" good or bad? (Viruses, Spyware and other Nasties)
- Help on SAS code (Computer Science)
Other Threads in the ASP.NET Forum
- Previous Thread: Any one knows good webhosting on ASP.NET
- Next Thread: [For Hire] Experienced ASP.NET/MSSQL Developer ($15/hour)
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox class click commonfunctions control countryselector dataaccesslayer database datagridview datagridviewcheckbox datalist deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iframe iis javascript listbox login microsoft mono mouse mssql news novell numerical opera panelmasterpagebuttoncontrols problem radio redirect registration relationaldatabases reportemail save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos vista visualstudio vs2008 web webapplications webdevelopemnt webdevelopment webprogramming webservice wizard xsl youareanotmemberofthedebuggerusers





