We help IT Professionals succeed at work.
Get Started

How to insert Data into SQL Server

98 Views
Last Modified: 2020-01-28
The code below works very well against Ms Access VBA but the same code does not insert anything against Ms SQL Server, any assistance will be highly appreciated. It seams like SQL does not like the command UPDATE I still think it wants a reference or Primary ID number while access accept without problems. The primary ID number cannot be there until the record is created, so in place of UPDATE  is there something that need to be done to insert the processed data into the SQL table????



Dim JSONS As Object

    lngStatus = CommRead(intPortID, strData, 14400)

Set rs = db.OpenRecordset("tblEfdReceipts")
    If lngStatus > 0 Then
    Set JSONS = JsonConverter.ParseJson(strData)
    Z = 2
    ElseIf lngStatus < 0 Then
    Beep
    MsgBox "Please note that there is no data to read", vbOKOnly, "The Comm Port has no data"
        ' Handle error.
        On Error Resume Next
    End If
        ' Process data.
  
  For Each Item In JSONS
           With rs
         
            .AddNew
            rs![TPIN] = Item("TPIN")
            rs![TaxpayerName] = Item("TaxpayerName")
            rs![Address] = Item("Address")
            rs![ESDTime] = Item("ESDTime")
            rs![TerminalID] = Item("TerminalID")
            rs![InvoiceCode] = Item("InvoiceCode")
            rs![InvoiceNumber] = Item("InvoiceNumber")
            rs![FiscalCode] = Item("FiscalCode")
            rs![TalkTime] = Item("TalkTime")
            rs![Operator] = Item("Operator")
            rs![Taxlabel] = Item("TaxItems")("TaxLabel")
            rs![CategoryName] = Item("TaxItems")("CategoryName")
            rs![Rate] = Item("TaxItems")("Rate")
            rs![TaxAmount] = Item("TaxItems")("TaxAmount")
            rs![TotalAmount] = Item("TaxItems")("TotalAmount")
            rs![VerificationUrl] = Item("TaxItems")("VerificationUrl")
            rs![INVID] = Me.InvoiceID
            rs.Update
        End With
        Z = Z + 1
    Next
      
      rs.Close
      Set rs = Nothing
      Set db = Nothing
      Set JSONS = Nothing

Open in new window



Regards

Chris
Comment
Watch Question
IT Supervisor
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 4 Answers and 6 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE