我在这里试图将dropdownlist值插入到我的sqldatabase
中,但它不起作用。你能帮我找到我做错了什么吗?无法将参数值从DropDownList转换为字符串
这对于下拉列表一些我的asp.net代码:
<p> Hardware Type :
<asp:DropDownList ID="DropDownList1" runat="server" Height="17px" Width="128px">
<asp:ListItem>Please Choose</asp:ListItem>
<asp:ListItem Value="laptop">Laptop</asp:ListItem>
<asp:ListItem Value="server">Server</asp:ListItem>
<asp:ListItem Value="television">Television</asp:ListItem>
<asp:ListItem Value="printer">Printer</asp:ListItem>
</asp:DropDownList>
这
一些我的下拉列表的.cs
comu.Parameters.Add("Hwtype", SqlDbType.VarChar, 50);
comu.Parameters["Hwtype"].Value = DropDownList1;
comu.Connection = con;
comu.ExecuteNonQuery();
con.Close();
}
}
我得到这个错误:Failed to convert parameter value from a DropDownList to a String.
应当'comu.Parameters [ “Hwtype”]值= DropDownList1.SelectedValue; ' – afzalulh
@afzalulh是的,它的工作。谢谢! – user3436232
请在发布之前在您的问题上提出问题,这个问题是非常基本的使用asp.net下拉列表。 –