使用vb.net更新多行

时间:2016-10-11 10:33:10

标签: mysql asp.net vb.net

我通过While循环从MySQL加载数据并列在表

<form id="form1" runat="server">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th style="text-align:left">id</th>
                            <th style="text-align:left">name</th>
                            <th style="text-align:center">color</th>                        </tr>
                </thead>
                <tbody>
                        <% 
                  Dim f1, f2, f3    
                    Dim rowcount, k, m As Integer

                    Dim connectionstring As String = ConfigurationManager.ConnectionStrings("DBstring").ConnectionString
                    Dim connectme As OdbcConnection = New OdbcConnection(connectionstring)
                  Dim ODBCdataset As DataSet = New DataSet()

                  Dim sqlquery As String = "SELECT * FROM table"

                  connectme.Open()
                  Dim ODBCdataadapter As OdbcDataAdapter = New OdbcDataAdapter(sqlquery, connectme)
                  ODBCdataadapter.Fill(ODBCdataset, "table")
                  connectme.Close()

                  k = 0
                  m = 1

                  rowcount = ODBCdataset.Tables("table").Rows.Count


                  Do While k < rowcount
                      f1 = ODBCdataset.Tables("ttemp").Rows(k).Item(0)
                      f2 = ODBCdataset.Tables("ttemp").Rows(k).Item(1)
                    %>

                    <tr>
                        <td align="center"><%Response.Write(f0)%></td>
                        <td align="center"><%Response.Write(f1)%></td>                          
                        <td><asp:DropDownList runat="server" ID="color">
                                <asp:ListItem Value=""></asp:ListItem>
                                <asp:ListItem Value="red">red</asp:ListItem>
                                <asp:ListItem Value="blue">blue</asp:ListItem>
                            </asp:DropDownList>
                        </td>                       </tr>
                </tbody>
                <%   
                    m = m + 1
                    k = k + 1
                Loop%></form>

表格(实际表格将有几百行)

id    name     color
1     AA       (dropdown)
2     BB       (dropdown)

我为用户添加了一个下拉列表,以便为每个ID选择他们喜欢的颜色。

现在,我如何一次性将所选颜色更新为MySQL?我假设它会像这样的循环?

UPDATE table SET color='" + color + "' WHERE id=  '" & id & "'"

如果答案太长,如果你能指出我正确的方向,我将不胜感激。

如果可能的话,如果用户没有为某个ID选择颜色,我可以跳过一行吗?

0 个答案:

没有答案
相关问题