How to insert a very large string into a table in SQL

It’s your job to go to them and say “this isn’t going to work, here’s why”

And I’ve never heard of a design stating specifics of “you have to use this code”

@nmjvk

Dont insert full…you can insert a part of it…like mentioned above just to check what all needs to be escaped and if it is working

Cheers

Dear Anil

I will try that. However, the string is much larger than simply “INSERT INTO dnb_api_rawdata VALUES (‘{"“transactionDetail"”:{"“transactionID"”:"“rrt-xxx-a-eu-x-xxxx"”}}’)”

cheers

@nmjvk

Agrred…this test is to check the escape charqcters…if this works…then we just need to use same for the big text also…and I hope your table can take a big text and your column datatype is setup accordingly

Cheers

Dear Anil

I just used your INSERT statement and it correctly inserts into the table without any problems. What should I substitute for the big text now if I might ask?

Cheers

@nmjvk

Instead of response1.ToString

Try with response1.ToString.Replace("""","\""")

Cheers

Dear Anil

I just tried your approach, however, I still encounter the same errors
image

And here is the full SQL statement using youir approach
“INSERT INTO MY_TABEL([COLUMN1]) VALUES ('” + response1.ToString.Replace(“”“”, “"”") + “')”

@nmjvk

Try this

URI.EscapeDataString(response1.ToString)

Also does your json contain any single quotes?

If there are then they needs to be escaped

Cheers

Dear Anil

I am now trying your other solution with URI.EscapeDataString(response1.ToString) and it is failing and also it is producing incorrect output.

To your other question, yes, my json does contain both " and ’ (so both double and single quote)

@nmjvk

as you have single and doubles lets try this

response1.ToString.Replace("""","\""").Replace("'","''")

cheers

1 Like

That is it. The solution works perfect. I just had to make an extra escape charatcer, which, when I think about it now makes sense. Thank you sir Anil the great for your help!

Cheerfully Cheers

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.