Hi,
Below is the code to update the table in sql database
code for Interface
[OperationContract]
[WebGet(UriTemplate = "UpdatePresidentById/{id}",
ResponseFormat = WebMessageFormat.Json)]
void UpdatePresidentById(string id);
cs code
public void UpdatePresidentById(string id)
{
string connStr = @"Data Source=WIN-941LO3JBRJG\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True;";
using (SqlConnection con = new SqlConnection(connStr))
{
string name = "zainobeta2";
//DataTable dt = new DataTable();
con.Open();
SqlCommand cmd = new SqlCommand("Update tblEmployee set Name = @name where ID=@id", con);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@id", id);
cmd.ExecuteNonQuery();
// con.Close();
cmd.Dispose();
}
}
jquery code
function updatePresidentsDataById() {var data1 = {
id: 2,
};
var serviceUri = _spPageContextInfo.webAbsoluteUrl +
"/_vti_bin/PresidentsService.svc/UpdatePresidentById";
$.ajax({
method: 'POST',
contentType: 'application/json;charset=utf-8',
url: serviceUri,
data: JSON.stringify(data1),
dataType: "json",
success:
function (response) {
alert('success');
},
error:
function (err) {
alert(JSON.stringify(err));
}
});
The table is not getting updated even after using PUT, also how to insert new values in the table using wcf rest jquery in sharepoint
Any suggestion plz, got stuck in above requirement for days.