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 28th, 2004, 07:55 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

I dont know what the Ole DB Services=-4; means i have looked through the beginners guide to asp.net vb.net 2003 and it seems to be in every connection string. i have tried to find somewhere in the book that breaks a connection string down and explains it but i cant find one. That is the only change i made to the web.config and the following is the new code for the params that you suggested to cut down on code. By style i meant this new cut down code (Sorry for the confusion).

<%@ Page Language="VB" Debug="true" %>
<%@ 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("connectionstrin g")

            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)

        dbCommand.Parameters.Add("@B_First_Name", OleDbType.VarChar, 10).Value = txtBFirstName.Text
        dbCommand.Parameters.Add("@B_Last_Name", OleDbType.VarChar, 10).Value = txtBLastName.Text
        dbCommand.Parameters.Add("@B_Add_1", OleDbType.VarChar, 15).Value = txtBAdd1.Text
        dbCommand.Parameters.Add("@B_Add_2", OleDbType.VarChar, 15).Value = txtBAdd2.Text
        dbCommand.Parameters.Add("@B_Town", OleDbType.VarChar, 10).Value = txtBTown.Text
        dbCommand.Parameters.Add("@B_PostCode", OleDbType.VarChar, 10).Value = txtBPostCode.Text
        dbCommand.Parameters.Add("@B_Country", OleDbType.VarChar, 15).Value = DropCountryList1.SelectedItem
        dbCommand.Parameters.Add("@B_Phone", OleDbType.VarChar, 15).Value = txtBPhone.Text
        dbCommand.Parameters.Add("@S_First_Name", OleDbType.VarChar, 10).Value = txtSFirstName.Text
        dbCommand.Parameters.Add("@S_Last_Name", OleDbType.VarChar, 10).Value = txtSLastName.Text
        dbCommand.Parameters.Add("@S_Add_1", OleDbType.VarChar, 15).Value = txtSAdd1.Text
        dbCommand.Parameters.Add("@S_Add_2", OleDbType.VarChar, 15).Value = txtSAdd2.Text
        dbCommand.Parameters.Add("@S_Town", OleDbType.VarChar, 10).Value = txtSTown.Text
        dbCommand.Parameters.Add("@S_PostCode", OleDbType.VarChar, 10).Value = txtSPostCode.Text
        dbCommand.Parameters.Add("@S_Country", OleDbType.VarChar, 15).Value = DropCountryList2.SelectedItem
        dbCommand.Parameters.Add("@S_Phone", OleDbType.VarChar, 15).Value = txtSPhone.Text
        dbCommand.Parameters.Add("@User_Name", OleDbType.VarChar, 15).Value = txtUserName.Text
        dbCommand.Parameters.Add("@Email", OleDbType.VarChar, 15).Value = txtEmail.Text
        dbCommand.Parameters.Add("@News_Opt_In", OleDbType.VarChar, 15).Value = NewsOptIn.Checked

        dbCommand.ExecuteNonQuery()
        dbConnection.Close()

    End Sub

</script>


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

Hey,

No problem. Is your code working, or are you still having issues?

Brian
 
Old July 28th, 2004, 09:16 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

I am still having trouble with this 500 error. I think I am going to simplify my original plans less forms etc and connect directly to the database. Once I know this "simple" version works then i will try harder things. I am keeping all the code i have done so far. I have started work on the simplified version, so far so good. Thanks for your help, I have a feeling I will be posting alot in the future.

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

Hey,

One thing you can try is binding to a datatable instead of a dataadapter. Because the DataReader is a live connection to the database, and you have to leave it open to bind to the grid. If you still want to use that, make the database connection a global variable. In addition, just so you know, you don't have to use the Interfaces (IDbConnection, IDataReader, etc), you can use the OleDbConnection, OleDbDataReader, etc.

Brian
 
Old July 28th, 2004, 11:57 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

I am still learning and use examples from the book i have and they always seem to be using IDbConnections etc so i thought that was norm.
I think that i need to learn more about databases do you know what the best book or web site to teach me about databases?

Cheers.

Dave

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

Hey,

IDbConnection allows you to use a SqlConnection, OleDbConnection, or other. If you use more than one database, or plan to switch in the future, maybe that would be the way to go. Otherwise...

What database do you want to learn? If you have Visual Studio .NET, you have a free copy of Personal SQL Server 2000 installed also. That is a good database to learn. Lately I've been mostly reading Microsoft press technical books.

Web sites typically can't give you the whole package, but are good to research specific functionality. You may find some that teach a good bit, but overall, a book is a great resource.

On the Oracle side, can't help you out, but there are plenty of books available. Don't know what Access or any other DB's resources are like.

Brian
 
Old July 28th, 2004, 03:50 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

I use Acces databases at the moment. I wouldnt mind getting Visual Studio .NET and its maybe something i could invest soon when i start uni this sept. SQL databases are something that i really want to learn i think i have the sql server installed already from when my friend was using my pc to code php. will ask him and take it from there. I really appreciate the help and advice.

Dave






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.