Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
ConnectionManager cm = new ConnectionManager();
           cm.Command.CommandText = "select * from tblFeedsItems where ItemID = '" + ((Button)sender).CommandArgument + "'";
           cm.Command.CommandType = CommandType.Text;
           cm.Connection.Open();
           SqlDataReader dr = cm.Command.ExecuteReader();
           while (dr.Read())
           {
               ListBox1.Items.Add("333", (dr["Title"].ToString()));
           }
           cm.Connection.Close();


the overload error is in line : ListBox1.Items.Add("333", (dr["Title"].ToString()));

why ????
Posted

1 solution

There is no overload that takes two items: just the one parameter representing the object to add.
If you want to add two objects, then consider calling Add twice, or using one of the AddRange overloads.
If you are trying to add an object with two properties, then you will need to create a container class, and add an instance of that instead:
C#
public class MyContainer
   {
   public string Number { get; set; }
   public string Title { get; set; }
   public MyContainer(string number, string title)
      {
      Number = number;
      Title = Title;
      }
   }
...
                ListBox1.Items.Add(new MyContainer("333", (dr["Title"].ToString())));
You will probably also want to override ToString in the container class to give a "sensible" human readable output.
 
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