本文介绍了将varchar值'System.Web.UI.WebControls.DropDownList'转换为数据类型int时,转换失败.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我收到错误消息将varchar值"System.Web.UI.WebControls.DropDownList"转换为数据类型int时转换失败."当我在下拉列表中输入数值时.谁能告诉我我哪里出了错
代码在这里
aspx
Hi all
I am getting the error "Conversion failed when converting the varchar value ''System.Web.UI.WebControls.DropDownList'' to data type int." when i enter numerical values into the drop down list . can any one tell me where i went wrong
code goes here
aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs" Inherits="Default7" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
#form1
{
height: 3px;
font-weight: 700;
}
</style>
</head>
<body bgcolor="#000000">
<form id="form1" runat="server">
<br />
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<br />
<asp:DropDownList ID="DropDownList2" runat="server" >
<asp:ListItem>0</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:DropDownList ID="DropDownList3" runat="server">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:DropDownList ID="DropDownList4" runat="server" AutoPostBack="True">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:DropDownList ID="DropDownList5" runat="server">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:DropDownList ID="DropDownList6" runat="server">
<asp:ListItem>0</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</form>
</body>
</html>
aspx.cs
aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
public partial class Default7 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
SqlConnection con = new SqlConnection("Data Source=ADMIN-PC;Initial Catalog=livemymoments;Integrated Security=True");
SqlCommand cmd;
SqlDataReader dr;
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
cmd = new SqlCommand("insert into marriage_config values('" + DropDownList1 + "','" + DropDownList2 + "','" + DropDownList3 + "','" + DropDownList4 + "','" + DropDownList5 + "','" + DropDownList6 + "')", con);
cmd.ExecuteNonQuery();
}
}
推荐答案
这篇关于将varchar值'System.Web.UI.WebControls.DropDownList'转换为数据类型int时,转换失败.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!