如何单独获取逗号分隔的SQL值的列表框 [英] How to retrieve commas delimited values in SQL to a ListBox separately

查看:141
本文介绍了如何单独获取逗号分隔的SQL值的列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL Server 2008中,其中每个值ID,我都插有逗号分隔值列表的表。

I have a table in SQL Server 2008, where for each value id, I have inserted a list of values with comma delimited.

所以在前端,当我选择从一个特定的ID的的DropDownList ,我想单独r​​etieve逗号分隔值代入到列表框

So In the front end, when I select a particular id from the DropDownList, I want to retieve the comma delimited values separately into to a ListBox.

希望我的问题是清楚的。好心帮...

Hope my question is clear. Kindly help...

推荐答案

试试这个

 //doing this in front end - C#
 string values = getValuesFromDB(dropdownList.SelectedValue);
 myListBox.DataSource = values.Split(',');
 myListBox.DataBind();

 foreach(string s in values.Split(','))
 {
   myListBox.Items.Add(s);
 }

有也回答了,这样说明如何convert CSV表并很为

There are also answers on SO that shows how to convert CSV to table and am sorry for not asking which SQL database you are using

更新

private string getValuesFromDB(string selectedID)
{
    //this might not be the rea; query
    string query = "SELECT commaValues FROM myTable WHERE id = " + selectedID; 
    ....
    ....
    string commaSeparatedValues = "retrieved values from this recod";
    return commaSeparatedValues;
}

这篇关于如何单独获取逗号分隔的SQL值的列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆