Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 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
  #1 (permalink)  
Old March 1st, 2006, 12:13 PM
Registered User
 
Join Date: Feb 2006
Location: Barnstaple, Devon, United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with class.......help

Right im trying to make a class of the following code:

Code:
 
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data

Public Class SQLStatements

    Public Function sqlSelect(ByVal sqlString)

        'Set up variables
        Dim MyConnection As String
        Dim sqlConnectionSelect As SqlConnection
        Dim Sql As SqlDataAdapter
        'Ser the dataset
        Dim DS As DataSet

        'Connect to database
        MyConnection = ConfigurationManager.AppSettings("ConnectionString")
        sqlConnectionSelect = New SqlConnection(MyConnection)

        Sql = New SqlDataAdapter(sqlString, sqlConnectionSelect)
        DS = New DataSet()
        Sql.Fill(DS, "Pages")

        sqlSelect = DS

    End Function

    Public Sub sqlInsert(ByVal sqlString)

        'Set up variables
        Dim MyConnection As String
        Dim sqlConnectionInsert As SqlCommand
        Dim Sql As SqlConnection

        'Set up connection to database
        MyConnection = ConfigurationManager.AppSettings("ConnectionString")
        Sql = New SqlConnection(MyConnection)

        'Perform insert
        sqlConnectionInsert = New SqlCommand(sqlString, Sql)

        'Execure insert
        sqlConnectionInsert.Connection.Open()
        sqlConnectionInsert.ExecuteNonQuery()
        sqlConnectionInsert.Connection.Close()

        'Close connection
        Sql.Close()

    End Sub
End Class
.

The select works perfectly, but when i try and pass across the insert statement via a click of a button like below...

Code:
 
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data
Imports SQLStatements
Imports System.Configuration
Imports System.Web
Imports System


Partial Class ben
    Inherits System.Web.UI.Page


    Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim doInsert As New SQLStatements
        doInsert.sqlInsert("INSERT INTO Pages (content) VALUES ('benny')")
    End Sub

End Class
I get the following error and I have no idea why and its doing my head in!!!

ERROR:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30002: Type 'SQLStatements' is not defined.

Source Error:



Line 13:
Line 14: Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Line 15: Dim doInsert As New SQLStatements
Line 16: doInsert.sqlInsert("INSERT INTO Pages (content) VALUES ('test')")
Line 17: End Sub
  #2 (permalink)  
Old March 1st, 2006, 02:29 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

What is the code you use for the Select?

  #3 (permalink)  
Old March 1st, 2006, 03:51 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Where did you store the class SQLStatements?

You may need to add a reference to it (when it's in a different project) or you may need to add a proper namespace to it...

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in Globals class pedroabs BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 8 June 12th, 2008 01:11 PM
Class building problem ps_kaushik C# 0 August 11th, 2006 06:48 AM
problem with using WebRequest class in C# anilkumarbv General .NET 0 December 28th, 2004 02:23 AM
Base Class for Code-Behind Problem groupmatch BOOK: ASP.NET Website Programming Problem-Design-Solution 3 September 8th, 2004 05:06 AM





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