Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 July 27th, 2004, 09:37 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default Please can you help with this Error

Hi there,

Any help would be appreciated. I am a beginner so dont laugh at my code! :)

The error first is:-

Compiler Error Message: BC30289: Statement cannot appear within a method body. End of method assumed.

Line 299: #End ExternalSource
Line 300:
Line 301: Public Sub New()
Line 302: MyBase.New
Line 303: Dim dependencies As System.Collections.ArrayList

Ok and now for the code.... its meant to be a user registration page. Also once the page has sent the information to the database and saved it i want it to go to a new page... how?

the code so far.

<%@ Page Language="VB" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

    Sub Page_Load()

        DropCountryList1.DataSource = CountriesList
        DropCountryList1.DataBind()

        DropCountryList2.DataSource = CountriesList
        DropCountryList2.DataBind()

    End Sub



    ' This will retrieves the countries from the databse


        Function CountriesList() As System.Data.IDataReader
            Dim connectionString As String = "ConfigurationSettings.AppSettings(connectionStrin g)"
            Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString )

            Dim queryString As String = "SELECT [Countries].[locName] FROM [Countries]"
            Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
            dbCommand.CommandText = queryString
            dbCommand.Connection = dbConnection

            dbConnection.Open
            Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

            Return dataReader
        End Function



    ' This is the submit button that will send all the information to the database

    Sub BtnSubmit_Click (sender as object, e as eventargs)

        Dim connectionString as string = "ConfigurationSettings.AppSettings(connectionStrin g)"
        Dim dbConnection As New OleDbConnection(connectionString)
            dbConnection.Open()

        Dim commandString as string = "INSERT INTO User_Details (B_First_Name, B_Last_Name, B_Add_1, B_Add_2, B_Town, B_PostCode, B_Country, B_Phone, S_First_Name, S_Last_Name, S_Add_1, S_Add_2, S_Town, S_PostCode, S_Country, S_Phone, User_Name, Password, Email, News_Opt_In) Values(@B_First_Name, @B_Last_Name, @B_Add_1, @B_Add_2, @B_Town, @B_PostCode, @B_Country, @B_Phone, @S_First_Name, @S_Last_Name, @S_Add_1, @S_Add_2, @S_Town, @S_PostCode, @S_Country, @S_Phone, @User_Name, @Password, @Email, @News_Opt_In)"

        Dim dbCommand as new OleDbCommand(commandString, dbConnection)

        Dim B_First_NameParam as new OleDbParameter("@B_First_Name", OleDbType.VarChar, 10)
            B_First_NameParam.Value = txtBFirstName.Text
            dbCommand.Parameters.Add(B_First_NameParam)

        Dim B_Last_NameParam as new OleDbParameter("@B_Last_Name", OleDbType.VarChar, 10)
            B_Last_NameParam.Value = txtBLastName.Text
            dbCommand.Parameters.Add(B_Last_NameParam)

        Dim B_Add_1Param as new OleDbParameter("@B_Add_1", OleDbType.VarChar, 10)
            B_Add_1Param.Value = txtBAdd1.Text
            dbCommand.Parameters.Add(B_Add_1Param)

        Dim B_Add_2Param as new OleDbParameter("@B_Add_2", OleDbType.VarChar, 10)
            B_Add_2Param.Value = txtBAdd2.Text
            dbCommand.Parameters.Add(B_Add_2Param)

        Dim B_TownParam as new OleDbParameter("@B_Town", OleDbType.VarChar, 10)
            B_TownParam.Value = txtBTown.Text
            dbCommand.Parameters.Add(B_TownParam)

        Dim B_PostCodeParam as new OleDbParameter("@B_PostCode", OleDbType.VarChar, 10)
            B_PostCodeParam.Value = txtBPostCode.Text
            dbCommand.Parameters.Add(B_PostCodeParam)

        Dim B_PhoneParam as new OleDbParameter("@B_Phone", OleDbType.VarChar, 10)
            B_PhoneParam.Value = txtBPhone.Text
            dbCommand.Parameters.Add(B_PhoneParam)

        Dim S_First_NameParam as new OleDbParameter("@S_First_Name", OleDbType.VarChar, 10)
            S_First_NameParam.Value = txtSFirstName.Text
            dbCommand.Parameters.Add(S_First_NameParam)

        Dim S_Last_NameParam as new OleDbParameter("@S_Last_Name", OleDbType.VarChar, 10)
            S_Last_NameParam.Value = txtSLastName.Text
            dbCommand.Parameters.Add(S_Last_NameParam)

        Dim S_Add_1Param as new OleDbParameter("@S_Add_1", OleDbType.VarChar, 10)
            S_Add_1Param.Value = txtSAdd1.Text
            dbCommand.Parameters.Add(S_Add_1Param)

        Dim S_Add_2Param as new OleDbParameter("@S_Add_2", OleDbType.VarChar, 10)
            S_Add_2Param.Value = txtSAdd2.Text
            dbCommand.Parameters.Add(S_Add_2Param)

        Dim S_TownParam as new OleDbParameter("@S_Town", OleDbType.VarChar, 10)
            S_TownParam.Value = txtSTown.Text
            dbCommand.Parameters.Add(S_TownParam)

        Dim S_PostCodeParam as new OleDbParameter("@S_PostCode", OleDbType.VarChar, 10)
            S_PostCodeParam.Value = txtSPostCode.Text
            dbCommand.Parameters.Add(S_PostCodeParam)

        Dim S_PhoneParam as new OleDbParameter("@S_Phone", OleDbType.VarChar, 10)
            S_PhoneParam.Value = txtSPhone.Text
            dbCommand.Parameters.Add(S_PhoneParam)

        Dim B_CountryParam as new OleDbParameter("@B_Country", OleDbType.VarChar, 15)
            B_CountryParam.Value = DropCountryList1.SelectedItem
            dbCommand.Parameters.Add(B_CountryParam)

        Dim S_CountryParam as new OleDbParameter("@S_Country", OleDbType.VarChar, 15)
            S_CountryParam.Value = DropCountryList2.SelectedItem
            dbCommand.Parameters.Add(S_CountryParam)

        dbCommand.ExecuteNonQuery()

        dbConnection.Close()

</script>
<!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>
    <title>DJ store</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link href="stylesheet.css" type="text/css" rel="stylesheet" />
</head>
<body>
    <form runat="server">

        <table cellspacing="0" cellpadding="0" width="100%" border="0">
            <tbody>
                <tr>
                    <td width="50%">
                        &nbsp;</td>
                    <td>

                        <table cellspacing="0" cellpadding="0" width="950" border="0">
                            <tbody>
                                <tr>
                                    <td class="topover" valign="top" width="151" height="60">
                                        <img height="60" src="images/logo.gif" width="151" /></td>
                                    <td class="topoverr" valign="top" width="799" height="60">
                                        &nbsp;</td>
                                </tr>
                                <tr>
                                    <td class="topmenu" align="middle" background="images/bar.gif" colspan="2" height="20">
                                        .: Home :: Categories :: Account Login :: Your Cart :: Checkout :.</td>
                                </tr>
                            </tbody>
                        </table>
                        <br />

                        <table cellspacing="0" cellpadding="0" width="950" border="0">
                            <tbody>
                                <tr>
                                    <td valign="top" width="150">
                                    </td>
                                    <td width="10">
                                        &nbsp;</td>
                                    <td valign="top" width="630">
                                        <p>
                                            Please complete the following form. All fields marked with * are
                                            required. If the shipping details are the same as the billing details then you can
                                            leave them blank.
                                        </p>
                                        <p>
                                            <strong>Billing Details:</strong>
                                        </p>
                                        <table cellspacing="0" cellpadding="0" width="630" border="0">
                                            <tbody>
                                                <tr>
                                                    <td width="120">
                                                        First Name:</td>
                                                    <td width="510">
                                                        <asp:TextBox id="txtBFirstName" runat="server" Width="300px"></asp:TextBox>
                                                        *</td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Last Name:</td>
                                                    <td>
                                                        <asp:TextBox id="txtBLastName" runat="server" Width="300px"></asp:TextBox>
                                                        *</td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Address Line 1:</td>
                                                    <td>
                                                        <asp:TextBox id="txtBAdd1" runat="server" Width="300px"></asp:TextBox>
                                                        *</td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Address Line 2:</td>
                                                    <td>
                                                        <asp:TextBox id="txtBAdd2" runat="server" Width="300px"></asp:TextBox>
                                                        *</td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Town/ City:</td>
                                                    <td>
                                                        <asp:TextBox id="txtBTown" runat="server" Width="300px"></asp:TextBox>
                                                        *</td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Post Code:</td>
                                                    <td>
                                                        <asp:TextBox id="txtBPostCode" runat="server" Width="300px"></asp:TextBox>
                                                        *</td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Country</td>
                                                    <td>

                                                        <asp:DropDownList id="DropCountryList1" runat="server"></asp:DropDownList>
                                                        *</td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Phone:</td>
                                                    <td>

                                                        <asp:TextBox id="txtBPhone" runat="server" Width="300px"></asp:TextBox>
                                                        </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                    </td>
                                                    <td>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                    </td>
                                                    <td>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <strong>
                                                        <br />
                                                        Shipping Details:</strong></td>
                                                    <td>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        &nbsp;<br />
                                                    </td>
                                                    <td>
                                                        &nbsp;</td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        First Name:</td>
                                                    <td>
                                                        <asp:TextBox id="txtSFirstName" runat="server" Width="300px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Last Name:</td>
                                                    <td>
                                                        <asp:TextBox id="txtSLastName" runat="server" Width="300px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Address Line 1:</td>
                                                    <td>
                                                        <asp:TextBox id="txtSAdd1" runat="server" Width="300px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Address Line 2:</td>
                                                    <td>
                                                        <asp:TextBox id="txtSAdd2" runat="server" Width="300px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Town/ City:</td>
                                                    <td>
                                                        <asp:TextBox id="txtSTown" runat="server" Width="300px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        Post Code:</td>
                                                    <td>
                                                        <asp:TextBox id="txtSPostCode" runat="server" Width="300px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
__________________
David Jenkins
 
Old July 27th, 2004, 12:04 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

I did a CTRL+F to look for Sub New, and couldn't find it in your code paste. From the error, it seems as if you may have nested it in another function. I did notice that there was no End Sub for btnSubmit_Click. That may be your issue.

In addition, thought you might like to know that you can shortcut your parameter declarations if you want to save code, by doing:

dbCommand.Parameters.Add("@S_Last_Name", OleDbType.VarChar, 10).Value = txtSLastName.Text

Brian
 
Old July 27th, 2004, 12:26 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Thank you for the tip on shortening the code :) its very much appreciated. I think you was right about the End Sub on the BtnSubmit. It now throws another error instead.

Format of the initialization string does not conform to specification starting at index 0.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

Line 20: Function CountriesList() As System.Data.IDataReader
Line 21: Dim connectionString As String = "ConfigurationSettings.AppSettings(connectionStrin g)"
Line 22: Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString )
Line 23:
Line 24: Dim queryString As String = "SELECT [Countries].[locName] FROM [Countries]"

What does the error mean? Clearly i can see its something to my database string but as far as i can see eveything is fine in web.config this is it:

<?xml version="1.0" encoding="UTF-8" ?>

<configuration>

         <appSettings>
            <add key="connectionstring" value="Provider=Microsoft.Jet.4.0; Data Source=C:\Inetpub\wwwroot\permissions\database\dat abase.mdb"/>
         </appSettings>



    <system.web>

    

    </system.web>

</configuration>
 
Old July 27th, 2004, 02:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

I think it might be this:

Dim connectionString As String = "ConfigurationSettings.AppSettings(connectionStrin g)"

The ConfigurationSettings.AppSettings(connectionString ) shouldn't be in quotes as shown. It should be:

Dim connectionString As String = ConfigurationSettings.AppSettings(connectionstring )

Brian
 
Old July 27th, 2004, 02:05 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Or

Dim connectionString As String = ConfigurationSettings.AppSettings("connectionstrin g")
 
Old July 27th, 2004, 02:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Oh yes, thank you for that catch Peter.
 
Old July 27th, 2004, 09:29 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Thank you both for your help :)

I changed to the connection string but also tried incorporating the new "method" to cut down code writing. But i think that i intepretated it wrong... Do i say Dim (new code style) or just enter[push enter] after dbCommand as new OleDbCommand(commandString, dbConnection) and input the new style... does that make sense?

dave


 
Old July 28th, 2004, 06:09 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

:D Woot! I think i kinda got the connection string sorted now. I went back to the beginners and went through it letter for letters. My web.config connect dtring was:

<appSettings>
            <add key="connectionstring" value="Provider=Microsoft.Jet.4.0; Data Source=C:\Inetpub\wwwroot\permissions\database\dat abase.mdb"/>
         </appSettings>

Should have been:
<appSettings>
            <add key="connectionstring" value="Provider=Microsoft.Jet.4.0; Ole DB Services=-4; Data Source=C:\Inetpub\wwwroot\permissions\database\dat abase.mdb"/>
         </appSettings>

Sorry for the trouble this has caused you and i thank you loads for helping me with it. :) I just have to work out why its now generating a HTTP 500 Internal Server Error... time to go through the book and find out if it has any info! :)
 
Old July 28th, 2004, 06:46 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Ok does anyone know how i can find out whats wrong with the page its generating and Http 500 Internal Server Error i cant seem to find anything about it in the beginners guide.

 
Old July 28th, 2004, 07:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

It's hard, because something is preventing it from showing. Basically, you need to look at what you've done between the time it worked and the time it didn't. It is usually based on a change. I've had that happen to me all the time.

I've never seen Ole DB Services=-4; declared in a connection string before. What does that do? That may be the change that's causing the problem...

I don't know what you mean by style, but for a sub new you do:

Public Sub New()

End Sub

OR

Public Sub New(<any params>)

End Sub

For setting a new OleDbCommand, you do:

Dim objCommand As New OleDbCommand("<command text>", objConnection)

Or

Dim objCommand As OleDbCommand = New OleDbCommand("<command text>", objConnection)

Or

Dim objCommand As OleDbCommand
objCommand = New OleDbCommand("<command text>", objConnection)

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
[Resolved] Error calling a sp - parameter error snufse .NET Framework 2.0 2 February 12th, 2008 04:46 PM
Parse error: syntax error, unexpected T_STRING ginost7 Beginning PHP 1 November 9th, 2007 02:51 AM
Phile Page error, visual studio error reps BOOK: ASP.NET Website Programming Problem-Design-Solution 0 September 27th, 2003 10:11 AM





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