Results 1 to 4 of 4

Thread: How to Use rest Api to post this Json data to SQLserver database

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2020
    Location
    Kampala
    Posts
    2

    How to Use rest Api to post this Json data to SQLserver database

    Please help me with a step by step in visual basic to post this json data to my sqlserver database

    {"status": "SUCCESSFUL", "msisdn": "256782123456", "initiation_date": "2019-10-21 09:03:03","completion_date": "2019-10-21 09:03:22", "amount": 20000, "receipt_number": "1587906379","reference_code": "c1a943f6-3f1aa162-95434a95-ef93f253-1aa43dc7"}

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,766

    Re: How to Use rest Api to post this Json data to SQLserver database

    What do you not understand about all the information and examples already available on the web? What have you tried and where are you stuck? If you haven't tried anything then you don't know what you can't do it yourself. Sites like this should be for the stuff you can't figure out for yourself, not the stuff you can't be bothered to figure out.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    33,068

    Re: How to Use rest Api to post this Json data to SQLserver database

    Try removing the eels from your hovercraft... there's a link in my sig that will help with this.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Re: How to Use rest Api to post this Json data to SQLserver database

    First create one database and then create one table into it.
    Code:
    use tempdb
    
    CREATE TABLE dbo.SystemRecord(
        RecordedDateTime        datetime2(0) NOT NULL,
        RecordedDateTimeLocal   datetime2(0) NOT NULL
    )
    Then create one stored procedure with one string parameter and write your code to insert data into a table.
    Code:
    CREATE PROCEDURE dbo.InsertSystemRecordData
     
    @json NVARCHAR(max)
    
    AS
    BEGIN
     
    INSERT INTO dbo.SystemRecord (
      [RecordedDateTime],
      [RecordedDateTimeLocal] 
        SELECT
            RecordedDateTime,
            RecordedDateTimeLocal
        FROM OPENJSON(@json)
        WITH (
          RecordedDateTime      DATETIME2(0) '$.dateTime',
          RecordedDateTimeLocal DATETIME2(0) '$.dateTimeLocal'
        ) AS jsonValues
     
    END
    After that execute the stored procedure by passing JSON as an INPUT parameter.

    Code:
    EXEC dbo.InsertSystemRecordData @json ='{"dateTime":"2018-03-19T15:15:40.222Z","dateTimeLocal":"2018-03-19T11:15:40.222Z"}'
    You can also check inserted data insert successfully or not with this query.

    Code:
    select * from dbo.SystemRecord

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width