I have a stored procedure in which there are multiple parameters, how to write a web api call that stored procedure with either using a single paramater or multiple parameters in a single web api get method using c#?
ALTER PROCEDURE [dbo].[STUDENT_DETAILS]
@STARTDATE DATETIME = NULL,
@ENDDATE DATETIME = NULL,
@STUDENTID INT = NULL,
@DEPTID INT = NULL,
@COLLEGEID INT = NULL,
@SECTIONID INT = NULL
[HttpGet]
[ActionName("getStudentDetails")]
public string getStudentDetails(string StartDate, string EndDate, int StudentId, int DeptId, int CollegeId, int SectionId)
{
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = ConfigurationManager.ConnectionStrings[""].ConnectionString;
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.CommandText = "STUDENT_DETAILS";
sqlCmd.Connection = myConnection;
sqlCmd.Parameters.AddWithValue("@StartDate", StartDate);
sqlCmd.Parameters.AddWithValue("@EndDate", EndDate);
sqlCmd.Parameters.AddWithValue("@StudentId", StudentId);
sqlCmd.Parameters.AddWithValue("@DeptId", DeptId);
sqlCmd.Parameters.AddWithValue("@CollegeId", CollegeId);
sqlCmd.Parameters.AddWithValue("@SectionId", SectionId);
SqlDataAdapter sda = new SqlDataAdapter(sqlCmd);
DataSet ds = new DataSet();
string jsonString = string.Empty;
myConnection.Open();
sda.Fill(ds);
myConnection.Close();
jsonString = JsonConvert.SerializeObject(ds.Tables[0]);
return jsonString;
}
If the user selects only start and end date, it must display the details based on only the start and end date, while keeping the other Id's as null. Likewise for all.
Note: single get method