Solved

Updation query in Access through VB.net

Posted on 2006-07-13
4
212 Views
Last Modified: 2010-04-23
Hello experts I am working on an application where I update the MsAccess database by coding. Now I am stuck with minor error but i did't able to rectify.
please tell me what's error in this code as it show me the syntax error
Private Sub updateAppNote()
        If AppConn.State.ToString = "Closed" Then
            AppConn.Open()
        End If
       
        Dim SQL As String = "UPDATE Applicant_Note " & _
        "set Time_Stamp='" & Now.ToShortDateString & " " & Now.ToShortTimeString & "', Note='" & txtnote.txt  & _
        "' Where NID=" & CLng(dgvNoteList.CurrentRow.Cells(0).Value)

        MsgBox(SQL)
        Dim Dc As New OleDbCommand(SQL, AppConn)
        Dc.ExecuteNonQuery()
        AppConn.Close()
0
Comment
Question by:EmmanuelNwokedi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 17100760
If AppConn.State = ConnectionState.Closed Then
            AppConn.Open()
        End If
0
 
LVL 35

Accepted Solution

by:
YZlat earned 50 total points
ID: 17103706
also when using Access database you should wrap Date values in #. Is Time_Stamp a string field or a date field?

If date, then do:

 Dim SQL As String = "UPDATE Applicant_Note " & _
        "set Time_Stamp=#" & Now & "#, Note='" & txtnote.txt  & _
        "' Where NID=" & CLng(dgvNoteList.CurrentRow.Cells(0).Value)

if it's a string, use

Dim SQL As String = "UPDATE Applicant_Note " & _
        "set Time_Stamp='" & Now.ToShortDateString.ToString & " " & Now.ToShortTimeString.ToString & "', Note='" & txtnote.txt  & _
        "' Where NID=" & CLng(dgvNoteList.CurrentRow.Cells(0).Value)

or

Dim SQL As String = "UPDATE Applicant_Note " & _
        "set Time_Stamp='" & Now.ToString & "', Note='" & txtnote.txt  & _
        "' Where NID=" & CLng(dgvNoteList.CurrentRow.Cells(0).Value)

0
 

Author Comment

by:EmmanuelNwokedi
ID: 17106640
Hello experts I am working on an application where I update the MsAccess database by coding. Now I am stuck with minor error but i did't able to rectify.
please tell me what's error in this code as it show me the "syntax error in update statement"
I try with every possible way still it show me the same error. Please Help me out
Private Sub updateAppNote()
        If AppConn.State.ToString = "Closed" Then
            AppConn.Open()
        End If
       
        Dim SQL As String = "UPDATE Applicant_Note " & _
        "set Time_Stamp='" & now & "', Note='" & txtnote.text  & _
        "' Where NID=" & CLng(dgvNoteList.CurrentRow.Cells(0).Value)

        MsgBox(SQL)
        Dim Dc As New OleDbCommand(SQL, AppConn)
        Dc.ExecuteNonQuery()
        AppConn.Close()
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17109142
Dim SQL As String = "UPDATE Applicant_Note " & _
        "set Time_Stamp=#" & now & "#, Note='" & txtnote.text  & _
        "' Where NID=" & CLng(dgvNoteList.CurrentRow.Cells(0).Value)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question