Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法将参数值从DropDownList转换为字符串_C#_Mysql_Asp.net_Sql_Database - Fatal编程技术网

C# 无法将参数值从DropDownList转换为字符串

C# 无法将参数值从DropDownList转换为字符串,c#,mysql,asp.net,sql,database,C#,Mysql,Asp.net,Sql,Database,我在这里试图将dropdownlist值插入我的sqldatabase,但它不起作用。你能帮我找出我做错了什么吗 这是dropdownlist的一些我的asp.net代码: <p> Hardware Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : <asp:DropDownList ID="DropDownList1" runat="server

我在这里试图将dropdownlist值插入我的
sqldatabase
,但它不起作用。你能帮我找出我做错了什么吗

这是dropdownlist的一些我的asp.net代码:

<p> Hardware Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :
    <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];