Click here to Skip to main content
15,909,827 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
List<string> txtItems = new List<string>();
           String dbValues;

           foreach (DataRow row in dt.Rows)
           {
               //String From DataBase(dbValues)
               dbValues = row["username"].ToString();
               dbValues = dbValues.ToLower();
               txtItems.Add(dbValues);
           }

           return txtItems.ToArray();
       }
Posted
Comments
Hariharan Arunachalam 28-Mar-13 4:56am    
What is the function signature? It seems that the function is intended to return a string..
navin ks 28-Mar-13 5:03am    
chech out solution1 comment

1 solution

Your method declaration defines that the return value is a string, you are trying to return an array of strings. Either change the method declaration to return an array, or tell us what string you want to return!
 
Share this answer
 
Comments
navin ks 28-Mar-13 5:02am    
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using MySql.Data.MySqlClient;
using System.Data;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace autocomplete
{
///
/// Summary description for WebService1
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 WebService1 : System.Web.Services.WebService
{

[WebMethod]
public string GetCompletionList(string prefixText, int count)
{
MySqlConnection con = new MySqlConnection("Server=localhost;Database=projecttt;Uid=root;Pwd=xxxxx;");
DataSet ds = new DataSet();
DataTable dt = new DataTable();

MySqlCommand cmd = new MySqlCommand();
cmd.CommandType = CommandType.Text;

cmd.CommandText = "select username from processeddata_table Where username like @myParameter";
cmd.Parameters.AddWithValue("@myParameter", "%" + prefixText + "%");

try
{
con.Open();
cmd.ExecuteNonQuery();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(ds);
}
catch
{
}
finally
{
con.Close();
}
dt = ds.Tables[0];

//Then return List of string(txtItems) as result
List<string> txtItems = new List<string>();
String dbValues;

foreach (DataRow row in dt.Rows)
{
//String From DataBase(dbValues)
dbValues = row["username"].ToString();
dbValues = dbValues.ToLower();
txtItems.Add(dbValues);
}

return txtItems.ToArray();
}
}
}
navin ks 28-Mar-13 5:02am    
what i need to change?
OriginalGriff 28-Mar-13 5:06am    
public string GetCompletionList(string prefixText, int count)
To
public string[] GetCompletionList(string prefixText, int count)
Probably...
navin ks 28-Mar-13 5:08am    
+5 thanks
OriginalGriff 28-Mar-13 6:09am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900