Hi all,
new to ASP.NET and having read several ASP.NET sites, Im very confused! I'm a pretty competent ASP programmer but the move to ASP.NET has got my head spinning.
Im just trying to program page which displays details for a specific product.In classic ASP all I did was use a recordset which accessed a MS SQL SProc ans then write all the fields to variables.
Im having problems in ASP.NET doing the same thing (I code in
VB). At the moment Im using a class like the following and just using labels around the ASPX page.
======== START OF CODE =========
Public Function GetBookDetails(ByVal ISBN As String) As BookDetails
' Create Instance of Connection and Command Object
Dim objConn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
Dim objCmd As SqlCommand = New SqlCommand("sp_Book_Detail", objConn)
' Mark the Command as a SPROC
objCmd.CommandType = CommandType.StoredProcedure
' Add Parameters to SPROC
Dim parameterISBN As SqlParameter = New SqlParameter("@ISBN", SqlDbType.VarChar, 10)
parameterISBN.Value = ISBN
objCmd.Parameters.Add(parameterISBN)
Dim parameterTitle As SqlParameter = New SqlParameter("@Title", SqlDbType.VarChar, 255)
parameterTitle.Direction = ParameterDirection.Output
objCmd.Parameters.Add(parameterTitle)
Dim parameterSubTitle As SqlParameter = New SqlParameter("@SubTitle", SqlDbType.VarChar, 255)
parameterSubTitle.Direction = ParameterDirection.Output
objCmd.Parameters.Add(parameterSubTitle)
Dim parameterAuthor As SqlParameter = New SqlParameter("@Author", SqlDbType.VarChar, 255)
parameterAuthor.Direction = ParameterDirection.Output
objCmd.Parameters.Add(parameterAuthor)
Dim parameterPublicationDate As SqlParameter = New SqlParameter("@PublicationDate", SqlDbType.VarChar, 100)
parameterPublicationDate.Direction = ParameterDirection.Output
objCmd.Parameters.Add(parameterPublicationDate)
Dim parameterDimensions As SqlParameter = New SqlParameter("@Dimensions", SqlDbType.VarChar, 10)
parameterDimensions.Direction = ParameterDirection.Output
objCmd.Parameters.Add(parameterDimensions)
Dim parameterNoPages As SqlParameter = New SqlParameter("@NoPages", SqlDbType.VarChar, 100)
parameterNoPages.Direction = ParameterDirection.Output
objCmd.Parameters.Add(parameterNoPages)
Dim parameterBinding As SqlParameter = New SqlParameter("@Binding", SqlDbType.VarChar, 100)
parameterBinding.Direction = ParameterDirection.Output
objCmd.Parameters.Add(parameterBinding)
Dim parameterPrice As SqlParameter = New SqlParameter("@Price", SqlDbType.Money, 8)
parameterPrice.Direction = ParameterDirection.Output
objCmd.Parameters.Add(parameterPrice)
Dim parameterDiscount As SqlParameter = New SqlParameter("@Discount", SqlDbType.Int, 4)
parameterDiscount.Direction = ParameterDirection.Output
objCmd.Parameters.Add(parameterDiscount)
' Open the connection and execute the Command
objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()
' Create and Populate BookDetails Struct using
' Output Params from the SPROC
Dim objBookDetails As BookDetails = New BookDetails()
objBookDetails.Title = CStr(parameterTitle.Value)
objBookDetails.SubTitle = CStr(parameterSubTitle.Value)
objBookDetails.Author = CStr(parameterAuthor.Value)
objBookDetails.PublicationDate = CStr(parameterPublicationDate.Value)
objBookDetails.Dimensions = CStr(parameterDimensions.Value)
objBookDetails.NoPages = CStr(parameterNoPages.Value)
objBookDetails.Binding = CStr(parameterBinding.Value)
objBookDetails.Price = CType(parameterPrice.Value, Decimal)
objBookDetails.Discount = CStr(parameterDiscount.Value)
Return objBookDetails
End Function
End Class
======== END OF CODE =========
The problem with the above (using Input/Output parameters) is I cant access Ntext or Text fields in the database. How do I go about doing this? Anyone show me the correct syntax or point me to an article?
Thanks!