Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i was used following code but i didnt get out put

C#
public void combo1sel()
{
SqlCommand com;
            SqlDataAdapter sda;
            DataSet ds;
            string str;
            var connectionString = ConfigurationManager.ConnectionStrings["newproject"].ConnectionString;
            SqlConnection cn = new SqlConnection(connectionString);

            str = "select contact_name +'              '+CAST(number as varchar(50)) as one from contact where contact_name='" + comboBox2.Text + "'";

            com = new SqlCommand(str, cn);
            sda = new SqlDataAdapter(com);
            ds = new DataSet();
            sda.Fill(ds, "contact");
            listBox2.DataSource = ds.Tables["contact"];
            listBox2.DisplayMember = "one";
            //listBox2.Text = "select";
            //listBox2.Text = "";
}

  private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox2.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
            var connectionString = ConfigurationManager.ConnectionStrings["newproject"].ConnectionString;
            SqlConnection cn = new SqlConnection(connectionString);
            cn.Open();
            try
            {
                SqlCommand cmd = new SqlCommand("select contact_name +'              '+CAST(number as varchar(50)) as one from contact where contact_name=('" + comboBox2.Text + "')", cn);
                SqlDataReader dbr;
                dbr = cmd.ExecuteReader();
               // checkedListBox1.Items.Clear();
                listBox2.Items.Clear();
                while (dbr.Read())
                {
                    //string eid = (string)dbr["eid"];
                    string name = (string)dbr["one"];
                    listBox2.Items.Add(name);
                  
                }
Posted
Updated 24-Sep-14 21:04pm
v3
Comments
Sergey Alexandrovich Kryukov 25-Sep-14 3:03am    
This is just code dump. (Format the code properly, please.)
Define: what do you mean by "get"?
—SA
ZurdoDev 25-Sep-14 8:55am    
What is your question? Debug it and find out what is wrong.

1 solution

From the title of your post, it seems you want to display a combobox that is capable of rendering multiple columns.  See this CP article:

/ravi
 
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