Wrox Programmer Forums
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals 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 August 19th, 2010, 05:18 AM
Registered User
 
Join Date: May 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default sql Helper

I have a lil web application that Iam developing that allows uploading of pics using the file upload control and saved into sql2005 in Binary format , however in my page to retrieve the photos getphoto.aspx I am getting an error saying SqlHelper is not delcared. the sql|Helper is a class file in my Appcode that contains Functions and methods to connect to database.


please can u assist me with this error I am thinking that I need to reference SqlHelper somewhere on my getphoto.aspx page but I am not sure where?

below is the page load section of my getphoto.aspx

Dim albumid As Integer = Convert.ToInt32(Request.QueryString("albumid"))
'Dim categoryID As Integer = Convert.ToInt32(Request.QueryString("CategoryID"))
Dim p() As SqlParameter = New SqlParameter(1) {}
p(0) = New SqlParameter("@albumid", albumid)
Dim isPublic As Boolean = Boolean.Parse(SqlHelper.ExecuteScalar("select ispublic from albums where albumid=@albumid", p).ToString())
If Not isPublic Then
If Not User.Identity.IsAuthenticated Then
Response.Redirect("~/login.aspx")
End If
End If

Dim albumid As Integer = Convert.ToInt32(Request.QueryString("albumid"))

'Dim categoryID As Integer = Convert.ToInt32(Request.QueryString("CategoryID"))

Dim p() As SqlParameter = New SqlParameter(1) {}

p(0) = New SqlParameter("@albumid", albumid)

Dim isPublic As Boolean = Boolean.Parse(SqlHelper.ExecuteScalar("select ispublic from albums where albumid=@albumid", p).ToString())

If Not isPublic Then

If Not User.Identity.IsAuthenticated Then

Response.Redirect("~/login.aspx")

End If

End If


and below is my sqlHelper

Imports Microsoft.VisualBasic

Imports System

Imports System.Data

Imports System.Data.SqlClient

Imports System.Configuration

Imports System.Web

Imports System.Web.Security

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Web.UI.WebControls.WebParts

Imports System.Web.UI.HtmlControls


Public Class SqlHelper

Inherits System.Web.UI.Page

Private Shared strConn As String


Shared Sub New()

strConn = ConfigurationManager.ConnectionStrings("myConnect" ).ConnectionString

End Sub

Public Shared Function ExecuteNonQuery(ByVal query As String) As Integer

Dim cnn As SqlConnection = New SqlConnection(strConn)

Dim cmd As SqlCommand = New SqlCommand(query, cnn)

cnn.Open()

Dim retval As Integer = cmd.ExecuteNonQuery()

cnn.Close()

Return retval

End Function

Public Shared Function ExecuteNonQuery(ByVal query As String, ByVal p() As SqlParameter) As Integer

Dim cnn As SqlConnection = New SqlConnection(strConn)

Dim cmd As SqlCommand = New SqlCommand(query, cnn)

FillParameters(cmd, p)

cnn.Open()

Dim retval As Integer = cmd.ExecuteNonQuery()

cnn.Close()

Return retval

End Function


Public Shared Function ExecuteReader(ByVal sql As String) As SqlDataReader

Dim cnn As SqlConnection = New SqlConnection(strConn)

Dim cmd As SqlCommand = New SqlCommand(sql, cnn)

Return cmd.ExecuteReader(CommandBehavior.CloseConnection)

End Function

Public Shared Function ExecuteReader(ByVal sql As String, ByVal p() As SqlParameter) As SqlDataReader

Dim cnn As SqlConnection = New SqlConnection(strConn)

Dim cmd As SqlCommand = New SqlCommand(sql, cnn)

FillParameters(cmd, p)

cnn.Open()

Return cmd.ExecuteReader(CommandBehavior.CloseConnection)

End Function

Public Shared Function ExecuteScalar(ByVal sql As String) As Object

Dim cnn As SqlConnection = New SqlConnection(strConn)

Dim cmd As SqlCommand = New SqlCommand(sql, cnn)

cnn.Open()

Dim retval As Object = cmd.ExecuteScalar()

cnn.Close()

Return retval

End Function


Public Shared Function ExecuteScalar(ByVal sql As String, ByVal p() As SqlParameter) As Object

Dim cnn As SqlConnection = New SqlConnection(strConn)

Dim cmd As SqlCommand = New SqlCommand(sql, cnn)

FillParameters(cmd, p)

cnn.Open()

Dim retval As Object = cmd.ExecuteScalar()

cnn.Close()

Return retval

End Function

Public Shared Function ExecuteDataSet(ByVal sql As String) As DataSet

Dim cnn As SqlConnection = New SqlConnection(strConn)

Dim cmd As SqlCommand = New SqlCommand(sql, cnn)

Dim da As SqlDataAdapter = New SqlDataAdapter()

da.SelectCommand = cmd

Dim ds As DataSet = New DataSet()

da.Fill(ds)

Return ds

End Function

Public Shared Function ExecuteDataSet(ByVal sql As String, ByVal p() As SqlParameter) As DataSet

Dim cnn As SqlConnection = New SqlConnection(strConn)

Dim cmd As SqlCommand = New SqlCommand(sql, cnn)

FillParameters(cmd, p)

Dim da As SqlDataAdapter = New SqlDataAdapter()

da.SelectCommand = cmd

Dim ds As DataSet = New DataSet()

da.Fill(ds)

Return ds

End Function

Private Shared Sub FillParameters(ByVal cmd As SqlCommand, ByVal parameters() As SqlParameter)

'Dim cmd As New SqlCommand(Sql, myConnection)

'Dim i As Integer

'For i = 0 To parameters.Length - 1 Step i + 1

' cmd.Parameters.Add(parameters(i))


'Next

End Sub

End Class
 
Old August 19th, 2010, 01:08 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Where did you store the SQLHelper class? In which folder exactly? And is this a web site project or a web application project?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
form helper blackhorse66 BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 0 June 24th, 2009 02:01 PM
Need of Helper and Global classes rajanikrishna BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 December 22nd, 2008 06:14 PM
1 quest on view helper hiteshp Struts 0 January 28th, 2008 03:06 AM
'helper' function? jtyson ASP.NET 1.0 and 1.1 Basics 1 June 29th, 2004 08:12 AM





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