Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this code returning one value, but I want display as 123,224,456,786 in textbox.

What I have tried:

[System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod(EnableSession = true)]
    public static List<string> employeeid(string prefixText, int count)
    {
        OracleConnection con = new OracleConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString.ToString());
        DataTable dtbl = new DataTable();
        OracleDataAdapter da = new OracleDataAdapter();
        List<string> Empid = new List<string>();
        try
        {
            string str = "select '3'|| emp_code || '0' as empcode from empmaster where '3'|| emp_code || '0' like '" + prefixText + "%'";
            dtbl = new DataTable();
            da = new OracleDataAdapter(str, con);
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            da.Fill(dtbl);
            for (int i = 0; i < dtbl.Rows.Count; i++)
            {
                Empid.Add(dtbl.Rows[i]["empcode"].ToString());
            }

            return Empid;
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }
Posted
Updated 16-Oct-18 2:37am
Comments
Leo Chapiro 24-Sep-18 5:43am    
>this code returning one value
I think this code returns a List<string>?
Now you need to parse this list and add a cooma or whatever between the parts?
Or what is exactly the problem here?
Darsh12345 24-Sep-18 5:58am    
I want to display multiple values in autocomplete textbox separated by comma. how to do it?
Member1x 25-Sep-18 2:55am    
OK, so let me get this straight. You got a List<string>. You link that somehow to your autocomplete textbox. So when you type something in that textbox, you want want somewhere shown the fitting emp_codes to that text, separated by comma? What do you get now? Only the first match?How and where do you format your results? Do you know which indices of your Empid-list you need to show? If yes you can do something like this:

string result = "";
int[] indices = {1, 4, 15, 16}; // Just an example; you need to get the indices by searching via RegEx for example
foreach (int i in indices)
{
   result += Empid[i] + ","; // Create your string with values separated by comma
}
result = result.TrimEnd(','); // Remove last comma

Now result should display what you want.
Richard Deeming 25-Sep-18 12:04pm    
catch (Exception ex)
{
    throw ex;
}

Don't do that! You've just thrown away the stack trace, making it much harder to find the real cause of the exception.

If you really want to re-throw an exception, just use throw; instead:
catch (Exception ex)
{
    throw;
}


But since you're not doing anything with the exception you've caught, you should simply remove the try..catch block instead.

1 solution

Your method returns object [List] containing string values. All you have do is parse the list as below :
eg:
var result = String.Join(",", new List<string> { '1', '2', '3', '4', '5' })
 
Share this answer
 

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