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