Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Services;
- using System.Web.Services.Protocols;
- using System.Xml.Linq;
- using System.Data.SqlClient;
- using System.Collections.Generic;
- namespace WebService10
- {
- /// <summary>
- /// Summary description for Service1
- /// </summary>
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [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 Service1 : System.Web.Services.WebService
- {
- [WebMethod]
- public String getData()
- {
- var names = new List<string>();
- SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=123");
- try
- {
- myConnection.Open();
- SqlCommand myCommand = new SqlCommand();
- myCommand.Connection = myConnection;
- myCommand.CommandText = "select name from names";
- SqlDataReader myReader = myCommand.ExecuteReader();
- while (myReader.Read())
- {
- names.Add(myReader["name"].ToString());
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- finally
- {
- myConnection.Close();
- }
- return string.Join("#", names.ToArray());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment