本文介绍了如何在c#.net的listbox表单组合框中获取多个coloumns的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了以下代码,但我没有退出



i was used following code but i didnt get out put

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);
                  
                }

推荐答案


这篇关于如何在c#.net的listbox表单组合框中获取多个coloumns的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 18:04