Olaide Azeez

Olaide Azeez

  • 1.7k
  • 67
  • 12.8k

how to access multiple column from database in webservice

Jul 15 2016 5:42 AM

The code below works well to retrieve one column but I need to retrieve multiple columns. 

using System;

using System.Collections.Generic;

using System.Web;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Data.SqlClient;

using System.Data;

using System.Data.Common;

//using AtlasTextBoxAutoComplete.DL;

using System.Collections;

/// <summary>

/// Summary description for actName

/// </summary>

[WebService(Namespace = "http://tempuri.org/")]

[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 actName : System.Web.Services.WebService {

SqlDataReader reader = null;

konnect kct = new konnect();

SqlConnection gap;

public actName () {

//Uncomment the following line if using designed components

//InitializeComponent();

gap = kct.myKonnection();

}

[WebMethod]

public string[] FindName(string prefixText)

{

gap.Open();

//return all records whose Title starts with the prefix input string

List<string> titleArList = new List<string>();

string sq = "select name from tblretainer where active = 1 and name like '%'+@pref+'%'";

SqlCommand cm = new SqlCommand(sq, gap);

cm.Parameters.AddWithValue("@pref", prefixText);

reader = cm.ExecuteReader();

while (reader.Read())

{

string strTemp = reader["name"].ToString();

titleArList.Add(strTemp);

}

return titleArList.ToArray();

gap.Close();

}

}


Answers (2)