Error converting DropDownList to Int32

0

I try to enter a value by means of a form and it generates this error, could you help me please

this is the form

 <asp:Table id="Table1" runat="server" CellPadding="8" GridLines="Both" 
        BorderColor="white" Height="419px" Width="500px">

    <asp:TableRow>
        <asp:TableCell> Tipo de documento</asp:TableCell>
        <asp:TableCell>
        <asp:DropDownList ID="tipo_doc" runat="server" Width="250px" BackColor="Transparent" DataSourceID="SqlDataSource1" DataTextField="tipo_doc" DataValueField="tipo_doc"></asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:GestorTICConnectionString %>" SelectCommand="Sp_TipoDoc"></asp:SqlDataSource>
        </asp:TableCell>
    </asp:TableRow>

    <asp:TableRow>
        <asp:TableCell>Número de documento</asp:TableCell>
        <asp:TableCell><asp:TextBox ID="num_doc" runat="server" Width="250px" BackColor="Transparent"></asp:TextBox></asp:TableCell>
    </asp:TableRow>

        <asp:TableRow>
        <asp:TableCell>Apellidos</asp:TableCell>
        <asp:TableCell> <asp:TextBox ID="apellidos" runat="server" Width="250px" BackColor="Transparent"></asp:TextBox> </asp:TextBox></asp:TableCell>
    </asp:TableRow>

        <asp:TableRow>
        <asp:TableCell>Nombres</asp:TableCell>
        <asp:TableCell><asp:TextBox ID="nombres" runat="server" Width="250px" BackColor="Transparent"></asp:TextBox></asp:TableCell>
    </asp:TableRow>

        <asp:TableRow>
        <asp:TableCell>E-mail </asp:TableCell>
        <asp:TableCell><asp:TextBox ID="email" runat="server" Width="250px" BackColor="Transparent"></asp:TextBox></asp:TableCell>
    </asp:TableRow>

        <asp:TableRow>
        <asp:TableCell>Telefono</asp:TableCell>
        <asp:TableCell><asp:TextBox ID="telefono" runat="server" Width="250px" BackColor="Transparent"></asp:TextBox></asp:TableCell>
    </asp:TableRow>

    <asp:TableRow>
        <asp:TableCell>Dirección</asp:TableCell>
        <asp:TableCell><asp:TextBox ID="direccion" runat="server" Width="250px" BackColor="Transparent"></asp:TextBox></asp:TableCell>
        </asp:TableRow>

     <asp:TableRow>
        <asp:TableCell>Número de cuenta</asp:TableCell>
        <asp:TableCell><asp:TextBox ID="cuenta_banco" runat="server" Width="250px" BackColor="Transparent"></asp:TextBox></asp:TableCell>
    </asp:TableRow>

    <asp:TableRow>
        <asp:TableCell>Estado</asp:TableCell>
        <asp:TableCell>
        <asp:DropDownList ID="estado" runat="server" Width="250px" BackColor="Transparent" DataSourceID="SqlDataSource2" DataTextField="tipo_estado" DataValueField="tipo_estado"></asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:GestorTICConnectionString %>" SelectCommand="Sp_TipoEstado"></asp:SqlDataSource>
        </asp:TableCell>
    </asp:TableRow>
    </asp:Table>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

        <asp:Table id="Table2" runat="server" CellPadding="8" GridLines="Both" 
        BorderColor="white" Height="418px" Width="500px">

     <asp:TableRow>
        <asp:TableCell>Vinculo</asp:TableCell>
        <asp:TableCell>
        <asp:DropDownList ID="vinculo" runat="server" Width="250px" BackColor="Transparent" DataSourceID="SqlDataSource4" DataTextField="tipo_vinculo" DataValueField="tipo_vinculo"></asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:GestorTICConnectionString %>" SelectCommand="Sp_TipoVin"></asp:SqlDataSource>
        </asp:TableCell>
    </asp:TableRow>

    <asp:TableRow>
        <asp:TableCell>Fecha de ingreso</asp:TableCell>
        <asp:TableCell><asp:TextBox type="date" ID="fec_ingreso" runat="server" Width="250px" BackColor="Transparent"></asp:TextBox></asp:TableCell>
    </asp:TableRow>

    <asp:TableRow>
        <asp:TableCell>Fecha de retiro</asp:TableCell>
        <asp:TableCell><asp:TextBox type="date" ID="fec_retiro" runat="server" Width="250px" BackColor="Transparent"></asp:TextBox></asp:TableCell>
    </asp:TableRow>

    <asp:TableRow>
        <asp:TableCell>Empresa real</asp:TableCell>
        <asp:TableCell>
        <asp:DropDownList ID="emreal" runat="server" Width="250px" BackColor="Transparent" DataSourceID="SqlDataSource5" DataTextField="IDempresa" DataValueField="IDempresa"></asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:GestorTICConnectionString %>" SelectCommand="Sp_TipoEmpre"></asp:SqlDataSource>
        </asp:TableCell>
    </asp:TableRow>

    <asp:TableRow>
        <asp:TableCell> Tipo de licencia</asp:TableCell>
        <asp:TableCell>
        <asp:DropDownList ID="tipo_licencia" runat="server" DataSourceID="SqlDataSource3" Width="250px" BackColor="Transparent" DataTextField="nom_licencia" DataValueField="nom_licencia"></asp:DropDownList>
        <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:GestorTICConnectionString %>" SelectCommand="Sp_TipoLicen"></asp:SqlDataSource>
        </asp:TableCell>
    </asp:TableRow>

    <asp:TableRow>
        <asp:TableCell>Número de licencia</asp:TableCell>
        <asp:TableCell><asp:TextBox ID="num_licencia" runat="server" Width="250px" BackColor="Transparent"></asp:TextBox></asp:TableCell>
    </asp:TableRow>

     <asp:TableRow>
        <asp:TableCell>Fecha de expedición</asp:TableCell>
        <asp:TableCell><asp:TextBox type="date" ID="fecha_exp" runat="server" Width="250px" BackColor="Transparent"></asp:TextBox></asp:TableCell>
    </asp:TableRow>

     <asp:TableRow>
        <asp:TableCell>Fecha de vencimiento</asp:TableCell>
        <asp:TableCell><asp:TextBox type="date" ID="fecha_ven" runat="server" Width="250px" BackColor="Transparent"></asp:TextBox></asp:TableCell>
    </asp:TableRow>
</asp:Table>

    <br />
    <br /><br /><br /><br />
    <div class="botones">
            <asp:Button ID="Button1" runat="server" Text="Insertar" Height="35px"
            Width="125px" />

And this is my Sql procedure

USE [GestorTIC]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Sp_TipoDoc]
AS
BEGIN
    SET NOCOUNT ON;

SELECT Conductores.IDTdocumento, Conductores.tipo_doc FROM TipoDocumento AS Conductores
INNER JOIN  TipoDocumento AS TipoDocumento ON
Conductores.tipo_doc = TipoDocumento.tipo_doc
END
    
asked by Angie Aroca 30.10.2018 в 21:56
source

1 answer

1

The problem is that you are assigning the references to the DropDownList as parameters, but you should pass it the selected value.

For example, you should replace this line:

cmd.Parameters.Add("@estado", SqlDbType.Int).Value = estado

by this line:

cmd.Parameters.Add("@estado", SqlDbType.Int).Value = Integer.Parse(estado.SelectedValue)

You should also put in the DataValueField property of each SqlDataSource the name of the field used as a key, which will be sent as a parameter to the stored procedure. The same with the rest of the values of the DropDownList.

Good luck!

    
answered by 30.10.2018 в 22:06