Method to pass 2 parameters to a PUT request in Fiddler

I am trying to update a single record in a table. The code is as follows:

public void UpdateStudent(int id, int studentClass)
{
    SqlConnection myConnection = new SqlConnection();

    myConnection.ConnectionString = @"Data Source=PALLAVI-PC\SQLEXPRESS;Initial Catalog=StudentDB;Integrated Security=True;MultipleActiveResultSets=True;";

    SqlCommand sqlCmd = new SqlCommand();
    sqlCmd.CommandType = CommandType.Text;
    sqlCmd.CommandText = "update Tbl_Students set Class="+ studentClass+" where Roll_Number=" + id + ";";

    sqlCmd.Connection = myConnection;

    myConnection.Open();

    int rowUpdated = sqlCmd.ExecuteNonQuery();
    myConnection.Close();
}

How can I pass both the id and the Class to the URL in fiddler?

Answers


You can do so using WCF REST Service. Implement following menthod and you can do what you want over fiddler:

[WebInvoke(Method = "PUT", UriTemplate = "api/student/{id}/{studentclass}")]
[OperationContract]
void UpdateEmployee(int id, int studentclass);

Kindly refer link for more detail on RESTFUL WCF Service.


Thanks for the help. I was able to solve the problem by changing my code slightly. The code is as follows:

    [HttpPut]
    [ActionName("UpdateStudent")]
    public void UpdateStudent(int id, [FromBody]Tbl_Students student)
    {
        SqlConnection myConnection = new SqlConnection();

        myConnection.ConnectionString = @"Data Source=PALLAVI-PC\SQLEXPRESS;Initial Catalog=StudentDB;Integrated Security=True;MultipleActiveResultSets=True;";

        SqlCommand sqlCmd = new SqlCommand();
        sqlCmd.CommandType = CommandType.Text;
        sqlCmd.CommandText = "update Tbl_Students set Class=" + student.Class + " where Roll_Number=" + id + ";";

        sqlCmd.Connection = myConnection;

        myConnection.Open();

        int rowUpdated = sqlCmd.ExecuteNonQuery();
        myConnection.Close();
    }

In Fiddler, I pass the id as a part of the URL and the studentClass as a JSON in the Request Body. I also added the Content-Type:application/json which I had forgotten to before. I have added the image below:


Need Your Help

Google closure: goog.require could not find: goog.ui

javascript google-closure

I'm learning google closure, and when I try to use the goog.ui component (any class thereof), I get the error goog.require could not find: goog.ui.

Overload index operator to mimic POD multi-dimensional array?

c++ arrays operator-overloading

I have an existing class, which is structured in the following way: