OLEDB Basics - I can't get it to work!

J

James Cooke

Hi all, please help me!
New to OLEDB in ASP.net, converting from SQL to OLEDB.

Below is a code snippet that executes under a connection that is known to be OK, since I can read the database using it OK.
I have highlighted the code for easier reading. Thanks in advance for any help!

--------------------------------------------------------------------------------

Private m_OLEDBConnection As System.Data.OleDb.OleDbConnection
Private m_ConnectionString As String

m_ConnectionString = System.Configuration.ConfigurationSettings.AppSettings("OLEDBConnectionString")
m_OLEDBConnection = New System.Data.OleDb.OleDbConnection(m_ConnectionString)
m_OLEDBConnection.Open()

This connection code works because it retrieves data OK

--------------------------------------------------------------------------------

Using the connection
Dim OLEDBCommandObject As System.Data.OleDb.OleDbCommand
Dim OLEDBParam As System.Data.OleDb.OleDbParameter
DIM SQL As String

SQL = "UPDATE Tree SET Site=@Site WHERE Tree=5612"

OLEDBCommandObject = New System.Data.OleDb.OleDbCommand(SQL, m_OLEDBConnection)

OLEDBParam = OLEDBCommandObject.Parameters.Add(New System.Data.oledb.OleDbParameter("@Site", System.Data.OleDb.OleDbType.Integer, 4))
OLEDBParam.Value = 1
OLEDBParam.SourceColumn = "Site"
Try
m_ReturnValue = OLEDBCommandObject.ExecuteScalar
Catch e As System.Data.SqlClient.SqlException
throw
End Try

The error comes up as follows

--------------------------------------------------------------------------------
Server Error in '/CPublisher' Application.
Must declare the variable '@Site'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Must declare the variable '@Site'.
 
M

Miha Markic [MVP C#]

Hi James,

Try with ? instead of @site within sql statement.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Hi all, please help me!
New to OLEDB in ASP.net, converting from SQL to OLEDB.

Below is a code snippet that executes under a connection that is known to be OK, since I can read the database using it OK.
I have highlighted the code for easier reading. Thanks in advance for any help!

------------------------------------------------------------------------------

Private m_OLEDBConnection As System.Data.OleDb.OleDbConnection
Private m_ConnectionString As String

m_ConnectionString = System.Configuration.ConfigurationSettings.AppSettings("OLEDBConnectionString")
m_OLEDBConnection = New System.Data.OleDb.OleDbConnection(m_ConnectionString)
m_OLEDBConnection.Open()

This connection code works because it retrieves data OK

------------------------------------------------------------------------------

Using the connection
Dim OLEDBCommandObject As System.Data.OleDb.OleDbCommand
Dim OLEDBParam As System.Data.OleDb.OleDbParameter
DIM SQL As String

SQL = "UPDATE Tree SET Site=@Site WHERE Tree=5612"

OLEDBCommandObject = New System.Data.OleDb.OleDbCommand(SQL, m_OLEDBConnection)

OLEDBParam = OLEDBCommandObject.Parameters.Add(New System.Data.oledb.OleDbParameter("@Site", System.Data.OleDb.OleDbType.Integer, 4))
OLEDBParam.Value = 1
OLEDBParam.SourceColumn = "Site"
Try
m_ReturnValue = OLEDBCommandObject.ExecuteScalar
Catch e As System.Data.SqlClient.SqlException
throw
End Try

The error comes up as follows

------------------------------------------------------------------------------
Server Error in '/CPublisher' Application.
Must declare the variable '@Site'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Must declare the variable '@Site'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top