G
Guest
I am using AutoComplete control in AJAX. I have following method in my web
service. But it is giving me following error
Cannot implicitly convert type 'string[]' to 'string'
[WebMethod]
public string FindEmails(string prefixText, int count)
{
ArrayList filteredList = new ArrayList();
String constr =
System.Configuration.ConfigurationManager.ConnectionStrings["MySqlServer"].ConnectionString;
SqlConnection objConn = new SqlConnection(constr);
SqlCommand objCmd = new SqlCommand("SELECT Emails From t_Users",
objConn);
SqlDataReader objRdr;
string[] str;
str = new string[12];
int x = 0;
int i = 0;
objConn.Open();
objRdr = objCmd.ExecuteReader();
while (objRdr.Read())
{
str[x] = Convert.ToString(objRdr.GetValue(i));
x = x + 1;
i = i + 1;
}
foreach (string name in str)
{
if (name.ToLower().StartsWith(prefixText.ToLower()))
filteredList.Add(name);
}
return (string[])filteredList.ToArray(typeof(string));
}
service. But it is giving me following error
Cannot implicitly convert type 'string[]' to 'string'
[WebMethod]
public string FindEmails(string prefixText, int count)
{
ArrayList filteredList = new ArrayList();
String constr =
System.Configuration.ConfigurationManager.ConnectionStrings["MySqlServer"].ConnectionString;
SqlConnection objConn = new SqlConnection(constr);
SqlCommand objCmd = new SqlCommand("SELECT Emails From t_Users",
objConn);
SqlDataReader objRdr;
string[] str;
str = new string[12];
int x = 0;
int i = 0;
objConn.Open();
objRdr = objCmd.ExecuteReader();
while (objRdr.Read())
{
str[x] = Convert.ToString(objRdr.GetValue(i));
x = x + 1;
i = i + 1;
}
foreach (string name in str)
{
if (name.ToLower().StartsWith(prefixText.ToLower()))
filteredList.Add(name);
}
return (string[])filteredList.ToArray(typeof(string));
}