C# 无法将参数值从DropDownList转换为字符串
我在这里试图将dropdownlist值插入我的C# 无法将参数值从DropDownList转换为字符串,c#,mysql,asp.net,sql,database,C#,Mysql,Asp.net,Sql,Database,我在这里试图将dropdownlist值插入我的sqldatabase,但它不起作用。你能帮我找出我做错了什么吗 这是dropdownlist的一些我的asp.net代码: <p> Hardware Type : <asp:DropDownList ID="DropDownList1" runat="server
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>
我收到此错误:
无法将参数值从DropDownList转换为字符串。
问题:您试图分配DropDownList
控件,而不是SelectedValue
替换此项:
comu.Parameters["Hwtype"].Value = DropDownList1;
为此:
comu.Parameters["Hwtype"].Value = DropDownList1.SelectedValue;
或
它应该是
comu.Parameters[“Hwtype”]。值=DropDownList 1.SelectedValue代码>@afzalugh是的,它能工作。谢谢请在发布之前搜索您的问题,所以,这个问题对于使用asp.net下拉列表是非常基本的。@Usama Khalil是的,我想我需要回到教程。。对不起,有时我忘了。。变老了…在问你关于Stackoverflow的问题之前,请用谷歌搜索你的答案。@Usama Khalil我用谷歌搜索了他们。。但大多数编码和我不完全一样。。。所以很难理解其他一些高级代码,然后像我一样理解基本代码。。。请理解,谢谢。
comu.Parameters["Hwtype"].Value = DropDownList1.SelectedValue;
comu.Parameters["Hwtype"].Value = DropDownList1.Items[DropDownList1.SelectedIndex];