简体   繁体   中英

Retrieve data from database column in WebMatrix

Im using WebMatrix 2. I need retrieve data from column in my database. This is database column:

在此输入图像描述

I have used this code to retrieve data and get it in combobox

@{
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>

With this code I get this result:

在此输入图像描述

But I need obtain this result:

在此输入图像描述

I tried many solutions, without success. Thanks in advance!

You need to split the value:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM