Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9178403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:32:35+00:00 2026-06-17T17:32:35+00:00

I have been struggling with this problem for a couple days, and have not

  • 0

I have been struggling with this problem for a couple days, and have not been able to find out what is wrong with the following code. When I click a button to update, nothing gets updated. By the way, I am using an html table to display a customer’s information, and then using those textboxes in the table to update the fields. But the SQL Update Statement just isn’t working. Here is the code:

Protected Sub btnUpdate_Click(sender As Object, e As System.EventArgs) Handles btnUpdate.Click

    Dim myConnection As OleDbConnection 

    Dim myCommand As OleDbCommand  

    Dim ID As Integer 

    Dim mySQLString As String, strFirstName As String, strLastName As String, strPhone As String, strEmail, strComment As String, Employee As String, DateCalled, TimeCalled, DateEdited As datetime 

    myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\wfccdb\datagridview\app_data\t3corp.mdb;")  

    myConnection.Open()  

    ID = Request.QueryString.Item("r") 

    Employee = tbEMP.Text  

    strFirstName = tbFname.Text

    strLastName = tbLname.Text

    strPhone = tbPhone.Text 

    strEmail = tbEmail.Text 

    DateCalled = Convert.ToDateTime(tbDateCalled.Text)  
    TimeCalled = Convert.ToDateTime(tbTimeCalled.Text)  
    strComment = tbComment.Text  
    DateEdited = Now

    mySQLString = "UPDATE customers SET Employee='" + Employee + "', FirstName='" + strFirstName + "', LastName='" + strLastName + "', Phone='" + strPhone + "', Email='" + strEmail + "', DateCalled='" + DateCalled + "', " + _
    "TimeCalled='" + TimeCalled + "', Comment='" + strComment + "', DateEdited='" + DateEdited + "' WHERE ReferenceID=" & Val(ID) & "" 

    myCommand = New OleDbCommand  

    myCommand.Connection = myConnection

    myCommand.CommandText = mySQLString

    myCommand.ExecuteNonQuery()
    myConnection.Close()



    Response.Redirect("ViewEditRecords.aspx?r=" + Request.QueryString.Item("r"))


End Sub 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:32:36+00:00Added an answer on June 17, 2026 at 5:32 pm

    your update SQL string contains a few problems. Let’s start from the beginning.

    mySQLString = "UPDATE customers SET Employee='" + Employee + "', FirstName='" + strFirstName + "', LastName='" + strLastName + "', Phone='" + strPhone + "', Email='" + strEmail + "', DateCalled='" + DateCalled + "', " + _
    "TimeCalled='" + TimeCalled + "', Comment='" + strComment + "', DateEdited='" + DateEdited + "' WHERE ReferenceID=" & Val(ID) & "" 
    

    First of all, notice the three date/time values you are trying to assign DateCalled, TimeCalled, DateEdited. I assume that they are real date values in your Access table. In this case you need to construct the update statement for the column as follows:

    ".... DateCalled=#" + tbDateCalled.Text + "# ...."
    

    (you need to surround the date value with #). Do this for TimeCalled as well.

    Now, have a look at your "' WHERE ReferenceID=" & Val(ID) & "". If you check what VAL function does, it is doing an opposite: converting string to number. So, in your case, you need to use (drop & "" as well, as there is no need for it):

    "' WHERE ReferenceID=" & CStr(ID)
    

    And finally, why don’t you check the error string after you call myCommand.ExecuteNonQuery(). I am pretty sure Access would tell you what the errors are

    So, to incorporate the suggestions from sgeddes, your final SQL string should look like this:

    Employee = Replace(Employee, "''", "'")
    Employee = Replace(Employee, "'", "''")
    Do this for first name, last name, phone, comment and email to minimise the threat of SQL injections
    
    mySQLString = "UPDATE customers SET Employee='" & Employee & "', FirstName='" & strFirstName & "', LastName='" & strLastName & "', Phone='" & strPhone & "', Email='" & strEmail & "', DateCalled=#" & tbDateCalled.Text & "#, " + _
    "TimeCalled=#" & tbTimeCalled.Text & "#, Comment='" & strComment & "', DateEdited=Now() WHERE ReferenceID=" & CStr(ID)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling to find a solution to this problem. In my code,
I have been struggling with a problem for a couple of days now with
I've been struggling for a couple of days now with this problem on QTcpSockets
I have been struggling with this issue for the past couple days: I have
I have been struggling with this for several days now and I ran out
I have been struggling with this problem, read many questions, articles but could not
For the last couple of days I have been struggling with the following issue
I´ve been struggling for several days with a problem. I have a couple of
I have been struggling with this problem for a few days now and I
I have been struggling to find an answer to this theoretical question, even tho

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.