我正在向表中添加行/记录;保存的其中一个值(应该表示从select元素中选择了两个选项中的哪一个)始终保存为" 0" - 我是选择第一个选项(索引0)还是第二个选项(索引1)。
以下是代码:
Dim Subcategory As String
. . .
If Request.Form.Item("Action") = "Save" Then
Unit = Request.Form.Item("Unit")
CustNo = Request.Form.Item("CustNo")
Subcategory = Request.Form.Item("selectSubcategory").ToString()
. .
Dim query2 As String = String.Empty
query2 &= "UPDATE Customers "
query2 &= "SET Subcategory = @SubCat "
query2 &= "WHERE MemberNo = @MemberNo AND Unit = @Unit AND CustNo = @CustNo "
Using conn As New SqlConnection("SERVER=PROSQL05;DATABASE=cpsdata;UID=sa;PWD=sqlsql")
Using comm As New SqlCommand()
With comm
.Connection = conn
.CommandType = CommandType.Text
.CommandText = query2
.Parameters.Add("@MemberNo", SqlDbType.NVarChar).Value = MemberNo
.Parameters.Add("@Unit", SqlDbType.NVarChar).Value = Unit
.Parameters.Add("@CustNo", SqlDbType.NVarChar).Value = CustNo
.Parameters.Add("@Subcat", SqlDbType.NVarChar).Value = Subcategory
End With
conn.Open()
comm.ExecuteNonQuery()
End Using 'comm
End Using 'conn
. . .
<select name="selectSubcategory" color="<%=Session("TextColor")%>" style="font: 8pt arial" onchange="UpdateFlag=true;">
<% If Not IsNewBusiness Then%>
<option <% If Subcategory = "0" Then Response.Write(" selected")%> value="0">Existing
<option <% If Subcategory = "1" Then Response.Write(" selected")%> value="1">Organic Growth
<% Else%>
<option <% If Subcategory = "0" Then Response.Write(" selected")%> value="0">New
<option <% If Subcategory = "1" Then Response.Write(" selected")%> value="1">Assumed
<% End If%>
</select>
单位和CustNo的存储方式与我输入时完全相同(文本框中的字符串值),但子类别始终为0.
在测试场景中,现有和有机增长是显示在&#34; selectSubcategory&#34;中的两个选项。选择元素。我是否选择&#34;有机增长&#34;或&#34;现有&#34;,0写入数据库。
为什么呢?我做错了什么?