-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStudentListWebService.cs
57 lines (49 loc) · 2.09 KB
/
StudentListWebService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
/// <summary>
/// StudentListWebService uses a ADO connection to a SQLServer database to retrieve a student record by ID
/// </summary>
[WebService(Namespace = "http://StudentListings.org/WebService")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class StudentListWebService : System.Web.Services.WebService
{
public StudentListWebService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public StudentRecord GetStudentById(int ID)
{
string CS = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("spGetStudentByID", con);
cmd.CommandType = CommandType.StoredProcedure;
//----create a parameter object for @ID
SqlParameter parameter = new SqlParameter("@ID", ID);
//--- associate parameter with command object
cmd.Parameters.Add(parameter);
StudentRecord studentRecord = new StudentRecord();
con.Open();
//--- cmd.ExecuteReader() returns a SqlDataReader object
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
studentRecord.StudentID = Convert.ToInt32(rdr["StudentID"]);
studentRecord.StudentName = Convert.ToString(rdr["StudentName"]);
studentRecord.StudentYear = Convert.ToString(rdr["StudentGrade"]);
studentRecord.StudentTotalMarks = Convert.ToInt32(rdr["StudentTotalMarks"]);
}
return studentRecord;
}
}
}