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 2nd, 2007, 12:04 PM
Authorized User
 
Join Date: Sep 2006
Posts: 82
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing Type value Error

Hi,

Within asp.net 1.1 and vb.net I want to display what item has been selected

from a drop down list. So for example if a customer clicks on Electric

Guitars, the text will display "Electric Guitars".

Within my Access database I have created a table called "tblType" that

assigns a value (TypeID) to each different item type. Also I have created a

function called "GetItemName" and assigned the variable TypeID.

Code:
 Function GetItemName(ByVal intTypeID As Integer) As Integer

        Dim item As String

        Dim strConnString As String = 

ConfigurationSettings.AppSettings.Get("ConnectionString")
        strConnString = String.Format(strConnString, 

Server.MapPath("\db\nwguitars.mdb"))
        Dim dbConnection As System.Data.IDbConnection = New 

System.Data.OleDb.OleDbConnection(strConnString)

        Dim queryString As String = "SELECT [tblType].[strTypeDetails] FROM 

[tblType] WHERE ([tblType].[intTypeID] = @"& _
        "intTypeID)"

        Dim dbCommand As System.Data.IDbCommand = New 

System.Data.OleDb.OleDbCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        Dim dbParam_intTypeID As System.Data.IDataParameter = New 

System.Data.OleDb.OleDbParameter
        dbParam_intTypeID.ParameterName = "@intTypeID"
        dbParam_intTypeID.Value = intTypeID
        dbParam_intTypeID.DbType = System.Data.DbType.Int32
        dbCommand.Parameters.Add(dbParam_intTypeID)

         'Open the db connection, run reader method and pass value via a 

datareader
        dbConnection.Open()
        Dim dataReader As System.Data.IDataReader = 

dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
        If dataReader.Read() Then
            item = dataReader.item("strTypeDetails")
        End If

        Return item
    End Function
Now I set a value called item which I return at the end of this function. I

then call this function and try to write out the value of "item" as :

Code:
 GetItemName(intTypeID)
            Response.Write(item)
However the result is thast just a zero is being written. Now I suspect

this is because the typeID value is not being passed. The intTypeID value

is obtained from a function called "GetItems" which obtains these values

from the option selected in the drop down list.

Any ideas where this is failing :

Code:
   'Function to get required items by typeID
     Function GetItems(ByVal intTypeID As Integer) As System.Data.DataSet

        'Database connection details
        Dim strConnString As String = 

ConfigurationSettings.AppSettings.Get("ConnectionString")
        strConnString = String.Format(strConnString, 

Server.MapPath("\db\nwguitars.mdb"))
        Dim dbConnection As System.Data.IDbConnection = New 

System.Data.OleDb.OleDbConnection(strConnString)

        'SQL statement to obtain product details based upon typeID
        Dim queryString As String = "SELECT tblMake.strMake, 

tblProducts.strProductName, tblColour.strColour, "& _
        "tblProducts.intQuantityInStock, tblProducts.curSalePrice, 

tblType.intTypeID, * "& _
        "FROM tblType INNER JOIN (tblMake INNER JOIN (tblColour INNER JOIN 

tblProducts ON "& _
        "tblColour.intColourID=tblProducts.intColourID) ON 

tblMake.intMakeID=tblProducts.intMakeID) "& _
        "ON tblType.intTypeID=tblProducts.intTypeID WHERE 

([tblProducts].[intTypeID] = @intTypeID)"

        'Command objects defined
        Dim dbCommand As System.Data.IDbCommand = New 

System.Data.OleDb.OleDbCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        'Define typeID parameter
        Dim dbParam_intTypeID As System.Data.IDataParameter = New 

System.Data.OleDb.OleDbParameter
        dbParam_intTypeID.ParameterName = "@intTypeID"
        dbParam_intTypeID.Value = intTypeID
        dbParam_intTypeID.DbType = System.Data.DbType.Int32
        dbCommand.Parameters.Add(dbParam_intTypeID)

        'Define datadapter
        Dim dataAdapter As System.Data.IDbDataAdapter = New 

System.Data.OleDb.OleDbDataAdapter
        dataAdapter.SelectCommand = dbCommand

        'Define and fill the dataset with the product information
        Dim dataSet As System.Data.DataSet = New System.Data.DataSet
        dataAdapter.Fill(dataSet)

        Return dataSet
     End Function
Apologies the the length of post but wanted to post enough details for

someone to assist - thanks

 
Old July 3rd, 2007, 07:45 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What does the query you provide in your code yield if you execute it in access?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
hi i got runtime error 13 Type Mismatch error sriharsha345 Access VBA 2 February 21st, 2008 09:30 AM
Error Type: (0x80004005) Unspecified error wilfree Classic ASP Databases 3 April 3rd, 2007 09:04 AM
Passing a Array in of no specifc type.. John Pennington Pro VB 6 1 September 27th, 2006 05:04 PM
ERROR TYPE youyou_hym Dreamweaver (all versions) 1 January 12th, 2005 03:13 AM
Data Type error but it is the correct type Mitch SQL Server 2000 2 March 19th, 2004 11:31 AM





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