Note that there are some explanatory texts on larger screens.

plurals
  1. POSolving No parameterless constructor defined for type of \u0027System.String\u0027
    primarykey
    data
    text
    <p>I've read through other responses to the same question, haven't been able to solve this. I'm trying to post a JSON string to my server (.NET), parse it and store some of the values - code is below. Everything works (ie the data ends up in my database, but it still throws the 500 error). Have looked into it with Fiddler etc but no success</p> <p>There are probably plenty of other issues in my code - it's just a bit of experimentation, for now, but would appreciate any advice...</p> <p>First, the jQuery post:</p> <pre><code>function PostData(value) { $.ajax({ type: "POST", url: "Default.aspx/PostData", data: JSON.stringify({ postedData: value }), contentType: "application/json", dataType: "json", success: function (msg) { console.log("success: " + msg.d); }, error: function (xhr, textStatus, error) { console.log("error:" + xhr.statusText + " " + textStatus + " " + error); } }); } </code></pre> <p>Next, the server side gear: </p> <pre><code>[WebMethod] public static string PostData(string postedData) { _PostData(postedData); return null; } public static void _PostData(string postedData) { JObject o = JObject.Parse(postedData); string id = (string)o.SelectToken("id"); using (SqlConnection sql = new SqlConnection(connectionString)) using (SqlCommand cmd = sql.CreateCommand()) { try { cmd.CommandText = "INSERT into Table1 (userId, data) VALUES (@userIdValue, @dataValue)"; cmd.Parameters.AddWithValue("@userIdValue", id); cmd.Parameters.AddWithValue("@dataValue", postedData); sql.Open(); cmd.Connection = sql; cmd.ExecuteNonQuery(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload