Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using MySQL and .NetCore. I have a table with Json data type. However, I am having trouble registering here via c #. I'm getting an error. How can I save Json data without destroying it?


DB Tablo
Id => type Int
Name => type nvarchar
JsonData => Type Json

I am saving Json data through database. But it gives an error with C # code.


What I have tried:

sqlconn = new MySqlConnection( ConnectionString );
      if (sqlconn.State != ConnectionState.Open)
      {
        sqlconn.Open();
       }
      cmd = new MySqlCommand("call Ynkys.sp_JSON_INSERT(2, 22, 'Test', '"+jsonString+"')", sqlconn);
      cmd.CommandType = CommandType.StoredProcedure;
      cmd.ExecuteNonQuery();



cmd.ExecuteNonQuery();
=>
ERROR:
{"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Test', '{\"Id\":\"22\",\"Name\":\"AAAAAAAAAA\"}')'' at line 1"}
Posted
Updated 26-Dec-20 15:43pm

1 solution

I don't think "call" works in this context. You need a (SP) name and parameters.

MySQL :: MySQL Connector/NET Developer Guide :: 6.1.5 Working with Stored Procedures[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900