Dear All,
I'm getting error with the following code. can anyone shortout the problem please. Your help is highly appreciated.
and calling procedure of this function as
I'm getting error with the following code. can anyone shortout the problem please. Your help is highly appreciated.
VB.NET:
Public Function GetProductDetails(ByVal productID As Integer) As ProductsDetails
' Create Instance of Connection and Command Object
Dim techConnection As OleDbConnection = New OleDbConnection(strConn)
Dim techCommand As OleDbCommand = New OleDbCommand("techProductDetails", techConnection)
' Mark the Command as a SPROC
techCommand.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterProductID As OleDbParameter = New OleDbParameter("@ProductID", OleDbType.Integer, 10)
parameterProductID.Value = productID
techCommand.Parameters.Add(parameterProductID)
Dim parameterUnitPrice As OleDbParameter = New OleDbParameter("@UnitPrice", OleDbType.Currency, 8)
parameterUnitPrice.Direction = ParameterDirection.Output
techCommand.Parameters.Add(parameterUnitPrice)
Dim parameterProductName As OleDbParameter = New OleDbParameter("@ProductName", OleDbType.VarChar, 50)
parameterProductName.Direction = ParameterDirection.Output
techCommand.Parameters.Add(parameterProductName)
' Open the connection and execute the Command
techConnection.Open()
techCommand.ExecuteNonQuery()
techConnection.Close()
' Create and Populate ProductDetails Struct using
' Output Params from the SPROC
Dim myProductDetails As ProductsDetails = New ProductsDetails
myProductDetails.ProductID = CStr(parameterProductID.Value)
myProductDetails.ProductName = CStr(parameterProductName.Value)
myProductDetails.UnitPrice = CType(parameterUnitPrice.Value, Decimal)
Return myProductDetails
End Function
and calling procedure of this function as
VB.NET:
Private Sub PopulateProductData()
Dim ProdID As Integer = CInt(txtProdID.Text)
Try
Dim ProductData As TechManagement.DBComponents.ProductDB = New TechManagement.DBComponents.ProductDB
Dim myProductDetails As TechManagement.DBComponents.ProductsDetails = ProductData.GetProductDetails(ProdID)
txtProdName.Text = myProductDetails.ProductName
MsgBox(myProductDetails.ProductName)
Catch e As OleDbException
MsgBox(e.Message)
End Try
End Sub