Click here to Skip to main content
15,910,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
public string[] GetCompletionList(string prefixText, int count)
    {
      //  DB cn = new DB();
        conn();
        DataTable dt = new DataTable();
        DataSet ds = new DataSet();
       
        try
        {
          
            string text = "%" + prefixText + "%";
            cmd = new SqlCommand("select * from product where name like '" + text + "'", con);
            da = new SqlDataAdapter(cmd);
            ds = new DataSet();
            da.Fill(ds);


          //  ds = cn.getDataSet("select * from reg where Firstname like '" + text + "'", "reg");
        }
        catch
        {
        }
        finally
        {
          

        }
        dt = ds.Tables[0];

        //Then return List of string(txtItems) as result
        List<string> txtItems = new List<string>();
        String dbValues;
        String img;
        String email;
        foreach (DataRow row in dt.Rows)
        {
            //String From DataBase(dbValues)

            dbValues = row["Email"].ToString();
            
            //dbValues = dbValues.ToLower();
            //txtItems.Add(dbValues,);

            img = row["image"].ToString();
           img = img.Remove(0, 2);
            
            //txtItems.Add(img);
           
            
            txtItems.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dbValues.ToString(), img.ToString()));


           // txtItems.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dbValues.ToString()));
        }

        return txtItems.ToArray();

    }

   
    
}



an error is this

C#
dt=ds.table[0];


Error msg : Cannot find table 0.

can any one solve it ...........!
Posted
Updated 10-Oct-12 2:35am
v2
Comments
bbirajdar 10-Oct-12 8:33am    
ben, did you try to debug the code? There must be no data in the sql table... The error simply means that the code has failed to fetch the data from the sql table...
MT_ 10-Oct-12 8:39am    
Do you know something called breakpoint and watch and all ?
[no name] 10-Oct-12 8:44am    
Milind ... You are rude in your comment.

first of all check whether your DB is returning the results or not. its most likely that database is returning null
secondly
to prevent app crashing , you may get the dataset this way...


C#
If(ds != null && ds.tables.count > 0)
{
dt = ds.Tables[0]
}
 
Share this answer
 
It looks like its not returning any tables.

Please make sure that your connection is proper, table exists and it returns table.
Put a breakpoint when filling into dataset and watch the values inside your adapter and dataset
 
Share this answer
 
Comments
kinjal b patel 13-Oct-12 2:36am    
i do hav the table and its working .........n connection is proper ....!
Try rhis code :

C#
  SqlDataAdapter sdaAdapter = new SqlDataAdapter();
 sdaAdapter.SelectCommand = new SqlCommand("select * from product where name like '" + text + "'", con);
 sdaAdapter.SelectCommand.CommandType =CommandType.Text;
DataTable dtTable = new DataTable();
sdaAdapter.Fill(dtTable);
 
Share this answer
 
v2
u try like this
C#
da.fill(ds,"write table name hear")
 
Share this answer
 
v2

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