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