Solved

ASP.NET command to insert values in sql database: Compiler Error Message: BC30451: Name 'CommandType' is not declared.

Posted on 2004-10-26
396 Views
Last Modified: 2008-02-01
Hello!! I have two questions:
1)Is the attached code the best way to insert data in sql database or you will reconmned to use another code?

2)Why it says Compiler Error Message: BC30451: Name 'CommandType' is not declared.

Code


<script runat="server">

      sub Button1_click(Sender As Object, E As EventArgs)

      Dim strConString As String
      Dim conlinklogisticoNET As SqlConnection
     strConString = ConfigurationSettings.AppSettings( "conString" )
      conlinklogisticoNET = New SqlConnection( strConString )

      conlinklogisticoNET.Open()
      Dim cmdinsert As SqlCommand
      cmdinsert = New SqlCommand( "sp_MTotalPurchaseInsert" , conlinklogisticoNET)
     cmdinsert.CommandType = CommandType.StoredProcedure


      Dim param1 as new sqlparameter
      param1.parametername = "@ponumber_x"
      param1.value = ponumber_x.text
      cmdinsert.parameters.add(param1, sqltype.nvarchar, 50)

       Dim param2 as new sqlparameter
      param2.parametername = "@date_x"
      param2.value = date_x.text
      cmdinsert.parameters.add(param2, sqltype.smalldatetime, 4)


       Dim param3 as new sqlparameter
      param3.parametername = "@no_do"
      param3.value = no_do.text
      cmdinsert.parameters.add(param3, sqltype.nvarchar, 50)


       Dim param4 as new sqlparameter
      param4.parametername = "@do_date"
      param4.value = do_date.text
      cmdinsert.parameters.add(param4, sqltype.smalldatetiem, 4)


       Dim param5 as new sqlparameter
      param5.parametername = "@supplier_x"
      param5.value = supplier_x.text
      cmdinsert.parameters.add(param5, sqltype.nvarchar, 50)


       Dim param6 as new sqlparameter
      param6.parametername = "@address"
      param6.value = address.text
      cmdinsert.parameters.add(param6, sqltype.nvarchar, 50)


       Dim param7 as new sqlparameter
      param7.parametername = "@tel"
      param7.value = tel.text
      cmdinsert.parameters.add(param7, sqltype.nvarchar, 50)


       Dim param8 as new sqlparameter
      param8.parametername = "@fax"
      param8.value = fax.text
      cmdinsert.parameters.add(param8, sqltype.nvarchar, 50)


       Dim param9 as new sqlparameter
      param9.parametername = "@email"
      param9.value = email.text
      cmdinsert.parameters.add(param9, sqltype.nvarchar, 50)


       Dim param10 as new sqlparameter
      param10.parametername ="@contact"
      param10.value = contact.text
      cmdinsert.parameters.add(param10, sqltype.nvarchar, 50)


       Dim param11 as new sqlparameter
      param11.parametername = "@city"
      param11.value = city.text
      cmdinsert.parameters.add(param11, sqltype.nvarchar, 50)


       Dim param12 as new sqlparameter
      param12.parametername = "@country"
      param12.value = country.text
      cmdinsert.parameters.add(param12, sqltype.nvarchar, 50)


       Dim param13 as new sqlparameter
      param13.parametername = "@buyer"
      param13.value = buyer.text
      cmdinsert.parameters.add(param13, sqltype.nvarchar, 50)


       Dim param14 as new sqlparameter
      param14.parametername = "@job"
      param14.value = job.text
      cmdinsert.parameters.add(param14, sqltype.nvarchar, 50)


       Dim param15 as new sqlparameter
      param15.parametername ="@emailbuyer"
      param15.value = emailbuyer.text
      cmdinsert.parameters.add(param15, sqltype.nvarchar, 50)

       Dim param16 as new sqlparameter
      param16.parametername = "@telbuyer"
      param16.value = telbuyer.text
      cmdinsert.parameters.add(param16, sqltype.nvarchar, 50)


       Dim param17 as new sqlparameter
      param17.parametername = "@client_name"
      param17.value = client_name.text
      cmdinsert.parameters.add(param17, sqltype.nvarchar, 50)


       Dim param18 as new sqlparameter
      param18.parametername = "@division_x"
      param18.value = division_x.text
      cmdinsert.parameters.add(param18, sqltype.decimal, 9)


       Dim param19 as new sqlparameter
      param19.parametername = "@via"
      param19.value = via.text
      cmdinsert.parameters.add(param19, sqltype.nvarchar, 50)


       Dim param20 as new sqlparameter
      param20.parametername = "@incoterms"
      param20.value = incoterms.text
      cmdinsert.parameters.add(param20, sqltype.nvarchar, 50)


       Dim param21 as new sqlparameter
      param21.parametername =  "@shipport"
      param21.value =  shipport.text
      cmdinsert.parameters.add(param21, sqltype.nvarchar, 50)


       Dim param22 as new sqlparameter
      param22.parametername = "@shipdestiny"
      param22.value = shipdestiny.text
      cmdinsert.parameters.add(param22, sqltype.nvarchar, 50)


       Dim param23 as new sqlparameter
      param23.parametername = "@cargo"
      param23.value = cargo.text
      cmdinsert.parameters.add(param23, sqltype.nvarchar, 50)


       Dim param24 as new sqlparameter
      param24.parametername = "@viapriority"
      param24.value = viapriority.text
      cmdinsert.parameters.add(param24, sqltype.nvarchar, 50)


       Dim param25 as new sqlparameter
      param25.parametername = "@shipto"
      param25.value = shipto.text
      cmdinsert.parameters.add(param25, sqltype.nvarchar, 50)



       Dim param26 as new sqlparameter
      param26.parametername ="@billto"
      param26.value = billto.text
      cmdinsert.parameters.add(param26, sqltype.nvarchar, 50)


        Dim param27 as new sqlparameter
      param27.parametername = "@notes"
      param27.value = notes.text
      cmdinsert.parameters.add(param27, sqltype.nvarchar, 2000)



    cmdinsert.executenonquery()
   conlinklogisticoNET.close()

    end sub

</script>
<html>
<head>
    <link href="..\styles\stylesheetwl.css" type="text/css" rel="stylesheet" />
</head>
<body>
    <form id="form" runat="server">
        <table marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">
            <tbody>
                <tr class="subtitle">
                    <td colspan="2">
                        <asp:Label id="poinfo" runat="server" width="240px">Orden de Compra</asp:Label></td>
                </tr>
                <tr class="1">
                    <td class="l">
                        <asp:Label id="lponumber_x" runat="server">Orden Compra</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="ponumber_x" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="2">
                    <td class="l">
                        <asp:Label id="ldate_x" runat="server">Fecha</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="date_x" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="1">
                    <td class="l">
                        <asp:Label id="lno_do" runat="server">No Do</asp:Label>&nbsp;
                    </td>
                    <td class="r">
                        <asp:TextBox id="no_do" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="2">
                    <td class="l">
                        <asp:Label id="ldo_date" runat="server">Fecha Do</asp:Label>&nbsp;</td>
                    <td class="r">
                        <asp:TextBox id="do_date" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="subtitle">
                    <td colspan="2">
                        <asp:Label id="supplierinfo" runat="server" width="245px">Informacin Proveedor</asp:Label></td>
                </tr>
                <tr class="1">
                    <td class="l">
                        <asp:Label id="lsupplier_x" runat="server">Proveedor</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="supplier_x" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="2">
                    <td class="l">
                        <asp:Label id="laddress" runat="server">Dirección</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="address" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="1">
                    <td class="l">
                        <asp:Label id="ltel" runat="server">Teléfono</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="Tel" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="2">
                    <td class="l">
                        <asp:Label id="lfax" runat="server">Fax</asp:Label></td>
                    <td>
                        <asp:TextBox id="fax" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="1">
                    <td class="l">
                        <asp:Label id="lemail" runat="server">Email</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="email" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="2">
                    <td class="l">
                        <asp:Label id="lcontact" runat="server">Contacto</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="contact" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="1">
                    <td class="l">
                        <asp:Label id="lcity" runat="server">Ciudad</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="city" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="2">
                    <td class="l">
                        <asp:Label id="lcountry" runat="server">Pais</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="country" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="subtitle">
                    <td colspan="2">
                        <asp:Label id="buyerinfo" runat="server" width="245px">Información Comprador</asp:Label></td>
                </tr>
                <tr class="1">
                    <td class="l">
                        <asp:Label id="lbuyer" runat="server">Comprador</asp:Label>Comprador</td>
                    <td class="r">
                        <asp:TextBox id="buyer" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="2">
                    <td class="l">
                        <asp:Label id="ljob" runat="server">Cargo</asp:Label>Cargo</td>
                    <td class="r">
                        <asp:TextBox id="job" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="1">
                    <td class="l">
                        <asp:Label id="lemailbuyer" runat="server">Email</asp:Label>Email
                    </td>
                    <td class="r">
                        <asp:TextBox id="emailbuyer" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="2">
                    <td class="l">
                        <asp:Label id="ltelbuyer" runat="server">Tel</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="telbuyer" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="1">
                    <td class="l">
                        <asp:Label id="lclient_name" runat="server">Cliente</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="client_name" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="2">
                    <td class="l">
                        <asp:Label id="ldivision_x" runat="server">Código Empresa</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="division_x" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="subtitle">
                    <td>
                        <asp:Label id="shippinginfo" runat="server">Instrucciones de Embarque</asp:Label></td>
                    <td>
                    </td>
                </tr>
                <tr class="1">
                    <td class="l">
                        <asp:Label id="lvia" runat="server">Medio Transporte</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="via" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="2">
                    <td class="l">
                        <asp:Label id="lincoterms" runat="server">Incoterms</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="incoterms" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="1">
                    <td class="l">
                        <asp:Label id="lshipport" runat="server">Puerto Embarque</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="shipport" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="2">
                    <td class="l">
                        <asp:Label id="lshipdestiny" runat="server">Puerto Destino</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="shipdestiny" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="1">
                    <td class="l">
                        <asp:Label id="lcargo" runat="server">Transportador</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="cargo" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="2">
                    <td class="l">
                        <asp:Label id="lviapriority" runat="server">Prioridad Transporte</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="viapriority" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="1">
                    <td class="l">
                        <asp:Label id="lshipto" runat="server">Embarcar a</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="shipto" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="2">
                    <td class="l">
                        <asp:Label id="lbillto" runat="server">Facturar a</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="billto" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="1">
                    <td class="l">
                        <asp:Label id="lnotes" runat="server">Notas</asp:Label></td>
                    <td class="r">
                        <asp:TextBox id="notes" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr class="2">
                    <td class="l">
                        <asp:Label id="lsystemdate" runat="server">Systemdate</asp:Label></td>
                    <td class="r">
                        <input type="hidden" name="systemdate" />
                    </td>
                </tr>
                <tr>
                    <td class="r" colspan="2">
                        <input type="reset" value="Reset" />
                        <asp:Button id="Button1" runat="server" onclick="Button1_click" Text="Submit"></asp:Button>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</body>
</html>

 
0
Question by:robossa
    4 Comments
     
    LVL 35

    Expert Comment

    by:mrichmon
    One thing I noticed (not related to your problem) is that you have a typo for parameter 4
    smalldatetiem --> smalldatetime

    I am looking at the error...
    0
     
    LVL 35

    Accepted Solution

    by:
    Have you tried adding the following imports?

    Imports System.Data
    Imports System.Data.SqlClient
    0
     

    Expert Comment

    by:genXerator
    i agree with mrichmon.  if it says CommandType is not declared, I imagine it is because of the line:

    cmdinsert.CommandType = CommandType.StoredProcedure

    If the appropriate classes are not present, it doesn't know what CommandType is.
    0
     

    Author Comment

    by:robossa
    It is working after including imports system.data. Thanks a lot  mrichmon. For genxerator, I kept the line cmdinsert thanks a lot.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    The Complete Ruby on Rails Developer Course

    Ruby on Rails is one of the most popular web development frameworks, and a useful tool used by both startups and more established companies to build strong graphic user interfaces, and responsive websites and apps.

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    This video teaches users how to migrate an existing Wordpress website to a new domain.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now