Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 3rd, 2003, 08:59 PM
Authorized User
 
Join Date: Aug 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inserting using a Stored Proc connection to SQL

Hello. When I Click my submit button. The data does not get added in to the database. I don't get an error messsage This is my code:
----------------------------------------------------------------
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Register.aspx.vb" Inherits="AIA.Register"%>
<%@Import Namespace="System.Data"%>
<%@Import Namespace="System.Data.SqlClient"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <title>Register</title>
        <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
        <meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
        <meta content="JavaScript" name="vs_defaultClientScript">
        <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <Script = Server>
        Public Sub AddMember(seneder as Object, e As EventArgs)

        // Establish Connection
        Dim myConnection As New SqlConnection
        Dim SQLServer As String = "Provider=SQLOLEDB.1;Data Source=localhost"
        Dim DataConn as SQLConnection
        DataConn = new SQLConnection(SQLServer)

        // Call to store procedure which will be executed in a moment
        dbCommand = New SQLCommand("sp_add_member",DataConn)

        // Our command type is for a store procedure. Not a string SQL statement
        dbCommand.CommandType = CommandType.StoredProcedure

        // We are inserting from a textboxes which will reference
        // the stored proc
        dbCommand.Parameters.Add(New SQLParameter("@MemFirstName", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemFirstName").Value = txtFirstName.Text.trim()

        dbCommand.Parameters.Add(New SQLParameter("@MemLastName", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemLastName").Value = txtLastName.Text.trim()

        dbCommand.Parameters.Add(New SQLParameter("@MemSpouseName", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemSpouseName").Value = txtSpouseName.Text.trim()

        dbCommand.Parameters.Add(New SQLParameter("@MemEmail", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemEmail").Value = txtAddress.Text.trim()

        dbCommand.Parameters.Add(New SQLParameter("@MemPhone", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemPhone").Value = txtCity.Text.trim()

        dbCommand.Parameters.Add(New SQLParameter("@MemAddress", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemAddress").Value = txtState.Text.trim()

        dbCommand.Parameters.Add(New SQLParameter("@MemChildrenNames", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemChildrenNames").Value = txtEmail.Text.trim()

        dbCommand.Parameters.Add(New SQLParameter("@MemChildrenNames", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemChildrenNames").Value = txtPhone.Text.trim()

        dbCommand.Parameters.Add(New SQLParameter("@MemChildrenNames", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemChildrenNames").Value = txtChildren.Text.trim()

        // Open connection and execute.
        // This is not a query so ExecuteNonQuery is used

        DataConn.open()
        dbCommand.ExecuteNonQuery
        DataConn.close
        //Response.Write("New person successfully added!")
        //Catch SQLexc As SqlException
        //Response.Write("Insert Failed. Error Details are: " & SQLexc.ToString())

        End Sub
    </Script>
    </HEAD>
    <body bgColor="#ccffff" MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <table>
                <tr>
                    <td>
                        <h2 align="center">AIA MEMBERSHIP[/h2]
                    </td>
                </tr>
                <tr>
                    <td>
                        Your membership dues are the life-line of AIA. In order to keep all function
                        ticket costs fairly low, all AIA functions (except India Day) are subsidized
                        from your yearly membership dues. We would appreciate your renewal of the year
                        2003 membership as soon as possible. If you have not already done so, please
                        complete the enclosed 2003 membership form and mail it with your check of $25
                        ($10 for students and temporary resident – non voting members) to AIA,
                    </td>
                </tr>
                <tr>
                    <td>
                        ($10.00Family-For families temporarily in Madison – Non Voting ___Life
                        Membership ($300-; Individual or Family)
                    </td>
                </tr>
                <tr>
                </tr>
                <tr align="center">
                    <td>
                        <asp:Label id="Label4" runat="server">First Name</asp:Label>
                        <asp:TextBox id="txtFirstName" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator id="RequiredFieldValidator1" ControlToValidate="txtFirstName" Text="Required Field!" runat="server" />
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        <asp:Label id="Label9" runat="server">Last Name</asp:Label>
                        <asp:TextBox id="txtLastName" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator id="Requiredfieldvalidator2" ControlToValidate="txtLastName" Text="Required Field!" runat="server" />
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        <asp:Label id="Label3" runat="server">Spouse Name</asp:Label>
                        <asp:TextBox id="txtSpouseName" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator id="Requiredfieldvalidator3" ControlToValidate="txtSpouseName" Text="Required Field!" runat="server" />
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        <asp:Label id="Label8" runat="server">Address</asp:Label>
                        <asp:TextBox id="txtAddress" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator id="Requiredfieldvalidator4" ControlToValidate="txtAddress" Text="Required Field!" runat="server" />
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        <asp:Label id="Label6" runat="server">City</asp:Label>
                        <asp:TextBox id="txtCity" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator id="Requiredfieldvalidator5" ControlToValidate="txtCity" Text="Required Field!" runat="server" />
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        <asp:Label id="Label2" runat="server">Zip</asp:Label>
                        <asp:TextBox id="txtZip" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator id="Requiredfieldvalidator6" ControlToValidate="txtZip" Text="Required Field!" runat="server" />
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        <asp:Label id="Label7" runat="server">Email</asp:Label>
                        <asp:TextBox id="txtEmail" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator id="Requiredfieldvalidator7" ControlToValidate="txtEmail" Text="Required Field!" runat="server" />
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        <asp:Label id="Label1" runat="server">Phone Number</asp:Label>
                        <asp:TextBox id="txtPhone" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator id="Requiredfieldvalidator8" ControlToValidate="txtPhone" Text="Required Field!" runat="server" />
                    </td>
                </tr>
                <tr align="center">
                    <td>
                        <asp:Label id="Label5" runat="server">Childrens Name</asp:Label>
                        <asp:TextBox id="txtchildren" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                </tr>
                <tr align="center">
                    <td>
                        <INPUT align="middle" type="button" onclick = "AddMember" value="Submit Form">
                    </td>
                </tr>
            </table>
        </form>
    </body>
</HTML>


Sanjeet
__________________
Sanjeet
 
Old August 5th, 2003, 07:32 PM
Authorized User
 
Join Date: Aug 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I get this error with my stored proc code:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30456: 'Value' is not a member of 'Integer'.

Source Error:



Line 31: Dim M_FirstName as String = txtFirstName.Text
Line 32: dbCommand.Parameters.add(New SQLParameter("@MemFirstName", SQLDbType.nvarchar,50))
Line 33: dbCommand.Parameters.add("@MemFirstName").Value = M_FirstName.Trim(M_FirstName)
Line 34:
Line 35: Dim M_LastName as String = txtLastName.Text


Source File: c:\inetpub\wwwroot\AIA\AIA\register.aspx Line: 33


Sanjeet
 
Old August 11th, 2003, 04:33 PM
Authorized User
 
Join Date: Aug 2003
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My insert works however the first value of each field gets cut. Would you know why this occurs. This is my code:

FirstName as String = txtFirstName.Text
        dbCommand.Parameters.add(New SQLParameter("@MemFirstName", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemFirstName").Value = M_FirstName.Trim(M_FirstName)

        Dim M_LastName as String = txtLastName.Text
        dbCommand.Parameters.add(New SQLParameter("@MemLastName", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemLastName").Value = M_LastName.Trim(M_LastName)

        Dim M_SpouseName = txtSpouseName.Text
        dbCommand.Parameters.add(New SQLParameter("@MemSpouseName", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemSpouseName").Value = M_SpouseName.Trim(M_SpouseName)

        Dim M_Address = txtAddress.Text
        dbCommand.Parameters.add(New SQLParameter("@MemAddress", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemAddress").Value = M_Address.Trim(M_Address)

        Dim M_City = txtCity.Text
        dbCommand.Parameters.add(New SQLParameter("@MemCity", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemCity").Value = M_City.Trim(M_City)

        Dim M_Zip = txtZip.Text
        dbCommand.Parameters.add(New SQLParameter("@MemZip", SQLDbType.int,9))
        dbCommand.Parameters("@MemZip").Value = M_Zip.Trim(M_Zip)

        Dim M_Email = txtEmail.Text
        dbCommand.Parameters.add(New SQLParameter("@MemEmail", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemEmail").Value = M_Email.Trim(M_Email)

        Dim M_Phone = txtPhone.Text
        dbCommand.Parameters.add(New SQLParameter("@MemPhone", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemPhone").Value = M_Phone.Trim(M_Phone)

        Dim M_Children = txtChildren.Text
        dbCommand.Parameters.add(New SQLParameter("@MemChildrenNames", SQLDbType.nvarchar,50))
        dbCommand.Parameters("@MemChildrenNames").Value = M_Children.Trim(M_Children)

-------------------------------------------------

<asp:Label id="Label4" runat="server">First Name</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;<asp:TextBox id="txtFirstName" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator id="RequiredFieldValidator1" ControlToValidate="txtFirstName" Text="Required Field!" runat="server" />
                        </p>
                        <p>
                            <asp:Label id="Label9" runat="server">Last Name</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;<asp:TextBox id="txtLastName" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator id="Requiredfieldvalidator2" ControlToValidate="txtLastName" Text="Required Field!" runat="server" />
                        </p>
                        <p>
                            <asp:Label id="Label3" runat="server">Spouse Name</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp :TextBox id="txtSpouseName" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator id="Requiredfieldvalidator3" ControlToValidate="txtSpouseName" Text="Required Field!" runat="server" />
                        </p>
                        <p>
                            <asp:Label id="Label8" runat="server">Address</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<asp:TextBox id="txtAddress" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator id="Requiredfieldvalidator4" ControlToValidate="txtAddress" Text="Required Field!" runat="server" />
                        </p>
                        <p>
                            <asp:Label id="Label6" runat="server">City</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a sp:TextBox id="txtCity" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator id="Requiredfieldvalidator5" ControlToValidate="txtCity" Text="Required Field!" runat="server" />
                        </p>
                        <p>
                            <asp:Label id="Label2" runat="server">Zip</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;<asp:TextBox id="txtZip" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator id="Requiredfieldvalidator6" ControlToValidate="txtZip" Text="Required Field!" runat="server" />
                        </p>
                        <p>
                            <asp:Label id="Label7" runat="server">Email</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a sp:TextBox id="txtEmail" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator id="Requiredfieldvalidator7" ControlToValidate="txtEmail" Text="Required Field!" runat="server" />
                        </p>
                        <p>
                            <asp:Label id="Label1" runat="server">Phone Number</asp:Label>&nbsp;&nbsp;&nbsp;<asp:TextBox id="txtPhone" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator id="Requiredfieldvalidator8" ControlToValidate="txtPhone" Text="Required Field!" runat="server" />
                        </p>
                        <p>
                            <asp:Label id="Label5" runat="server">Childrens Name</asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;<asp:TextBox id="txtchildren" runat="server"></asp:TextBox>
                            <asp:RequiredFieldValidator id="Requiredfieldvalidator9" ControlToValidate="txtPhone" Text="Required Field!" runat="server" />

Sanjeet





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling an insert stored proc from a select stored dzitam SQL Language 10 April 2nd, 2007 12:39 PM
MS Access .mdb calling SQL server 2000 stored proc fazzou Access 6 September 8th, 2006 11:32 AM
Return output variable to VB from SQL stored proc busterbunny BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 March 27th, 2006 10:24 PM
Calling a T-SQL Stored proc from DTS mepancha SQL Server 2000 1 April 13th, 2005 09:12 AM
sql statements and stored proc. HOW????? xristina MySQL 3 October 24th, 2004 07:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.