using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; namespace RohitWebService { /// <summary> /// Summary description for RohitService /// </summary> [WebService(Namespace = "http://Rohitshukla.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 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 RohitService : System.Web.Services.WebService { [WebMethod] public string HelloRohit() { return "code is done by Rohit Shukla"; } [WebMethod] public List<String>[] Marks(string sem) { List<String>[] data = semester.marks(sem); return data; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using MySql.Data.MySqlClient; namespace RohitWebService { public class semester { public static List<String>[] marks(String mark1) { int i = 0; //Create a list to store the result List<string>[] list = new List<string>[4]; list[0] = new List<string>(); list[1] = new List<string>(); list[2] = new List<string>(); list[3] = new List<string>(); String mysqlconnection = "server=localhost;;database=rohit_marks;uid=root;password=root;"; MySqlConnection connection = new MySqlConnection(mysqlconnection); MySqlCommand cmd; connection.Open(); try { //Create Command cmd = connection.CreateCommand(); cmd.CommandText = "select * from marks where sem = @sem ;"; cmd.Parameters.AddWithValue("@sem", mark1); cmd.ExecuteNonQuery(); //Create a data reader and Execute the command MySqlDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { list[0].Add(dataReader["subject"] + ""); list[1].Add(dataReader["sem"] + ""); list[2].Add(dataReader["mark_obtained"] + ""); } //close Data Reader dataReader.Close(); } catch (MySqlException) { throw; } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } return list; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)