从WebMatrix中的数据库列检索数据

时间:2013-05-02 10:30:20

标签: c# asp.net sql webmatrix

我正在使用WebMatrix 2.我需要从数据库中的列中检索数据。这是数据库列:

enter image description here

我已使用此代码检索数据并在组合框中获取

@{
var db1 = Database.Open("StarterSite");
var selectCommand = "SELECT Motivo FROM Set_Residenziali";
var selectedData = db1.Query(selectCommand); 
}

<select name="motivo">
    @foreach(var row in selectedData)
    {
        <option value="@row.Motivo">@row.Motivo</option>
    }
</select>

使用此代码我得到了这个结果:

enter image description here

但我需要获得这个结果:

enter image description here

我尝试了很多解决方案,没有成功。提前谢谢!

1 个答案:

答案 0 :(得分:3)

您需要拆分值:

<select name="motivo">
    @foreach(var row in selectedData){
        foreach(var item in row.Motivo.ToString().Split(new [] {','})){
        <option>@item</option>
        }
    }
</select>
相关问题