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

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

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

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top