AutoComplete control

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));

}
 
A

Alexey Smirnov

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));

The column is always the same, you have only one column ("SELECT
Emails..."). So, just change objRdr.GetValue(i) into
objRdr.GetValue(0) and try again.
 
A

Alexey Smirnov

I am using AutoComplete control in AJAX. I have following method in myweb
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));

The column is always the same, you have only one column ("SELECT
Emails..."). So, just change objRdr.GetValue(i) into
objRdr.GetValue(0) and try again.- Hide quoted text -

- Show quoted text -

you also don't need to loop twice and get all rows from the database
when you know that you would need only email addresses started with
the prefix prefixText

1) change your sql query to return only rows you would need

prefixText = prefixText.replace("'", "''");
"SELECT Emails From t_Users WHERE Emails LIKE '" + prefixText + "%'"

2) get rid of foreach (string name in str), because you don't need it

3) int i = 0; is never used
 
M

marss

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)
{ .....
}
return (string[])filteredList.ToArray(typeof(string));

}

You try to return value that type (string[]) differs from one defined
by function signature (string).

Regards,
Mykola
http://marss.co.ua
 
A

Alexey Smirnov

You try to return value that type (string[]) differs from one defined
by function signature (string).

0) ah, yes, that was the initial error there!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top