列表框控件问题

问题描述:

Hai,



我有一个包含多选项选项的列表框。如果我想在sql中的特定列中插入这些值,则表示它不能正常工作。它显示在SQL列中出现错误System.Collections.Generic.List`1 [System.String]。请帮助解决此问题



Hai,

I have a listbox that contains multiselect options.Suppose if i want to insert those values in particular column in sql it is not working.It showing error"System.Collections.Generic.List`1[System.String]" in sql column.Please help to fix this issue

var selected = ListBox1.GetSelectedIndices().ToList();
            var selectedValues = (from c in selected
                                  select ListBox1.Items[c].Value).ToList();

            SqlCommand cmd = new SqlCommand("insert into Catalog1(System)values('" + selectedValues + "')", con);
            cmd.ExecuteNonQuery();
            con.Close();

HI


试试这段代码...







HI
Try this code...



var selected = ListBox1.GetSelectedIndices().ToList();
                var selectedValues = (from c in selected
                                      select ListBox1.Items[c].Text).ToList();

                foreach (string value in selectedValues)
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("insert into Catalog1(System)values('" + value + "')", con);
                    cmd.ExecuteNonQuery();
                    con.Close();

                }