Hi nagaraju60,
You just create a class and return List from the class, then call the class in Web Service.
Check this example. Now please take its reference and correct your code.
DataAccess.cs
public List<string> GetCustomerIds(string prefixText)
{
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ToString());
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("select ContactName,CustomerId from Customers where ContactName like @SearchText + '%'", con);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.AddWithValue("@SearchText", prefixText);
con.Open();
List<string> customerIds = new List<string>();
using (System.Data.SqlClient.SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(sdr["ContactName"].ToString(), sdr["CustomerId"].ToString());
customerIds.Add(item);
}
sdr.Close();
}
con.Close();
return customerIds;
}
DataAccess.vb
Public Function GetCustomerIds(ByVal prefixText As String) As List(Of String)
Dim con As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("constr").ToString())
Dim cmd As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("select ContactName,CustomerId from Customers where ContactName like @SearchText + '%'", con)
cmd.CommandType = System.Data.CommandType.Text
cmd.Parameters.AddWithValue("@SearchText", prefixText)
con.Open()
Dim customerIds As List(Of String) = New List(Of String)()
Using sdr As System.Data.SqlClient.SqlDataReader = cmd.ExecuteReader()
While sdr.Read()
Dim item As String = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(sdr("ContactName").ToString(), sdr("CustomerId").ToString())
customerIds.Add(item)
End While
sdr.Close()
End Using
con.Close()
Return customerIds
End Function
asmx webservice
CS
[WebMethod]
public List<string> SearchUsrId(string prefixText, int count)
{
DataAccess data = new DataAccess();
List<string> Usr_Id = data.GetCustomerIds(prefixText);
return Usr_Id;
}
VB.Net
<WebMethod>
Public Function SearchUsrId(ByVal prefixText As String, ByVal count As Integer) As List(Of String)
Dim data As DataAccess = New DataAccess()
Dim Usr_Id As List(Of String) = data.GetCustomerIds(prefixText)
Return Usr_Id
End Function
Then call the web service in aspx page.