VB Scalar Declaration Error

M

m1c

I get the following error when I debug my program:
ERROR [42000] [Microsoft][SQL Native Client][SQL Server]Must declare
the scalar variable "@dbOfficeName".

It throws the error on this statement:

SQLOfficeData.ExecuteNonQuery()

Which is defined as:
Dim SQLOfficeData = New OdbcCommand("DECLARE OfficeData CURSOR FOR
SELECT @dbOfficeName FROM Office ORDER BY @dbOfficeName", dbConn)


I declared @OfficeName like this:
Dim OfficeName = New OdbcParameter("@dbOfficeName", OdbcType.Char)

So.... where to go now?
 
L

Lloyd Sheen

m1c said:
I get the following error when I debug my program:
ERROR [42000] [Microsoft][SQL Native Client][SQL Server]Must declare
the scalar variable "@dbOfficeName".

It throws the error on this statement:

SQLOfficeData.ExecuteNonQuery()

Which is defined as:
Dim SQLOfficeData = New OdbcCommand("DECLARE OfficeData CURSOR FOR
SELECT @dbOfficeName FROM Office ORDER BY @dbOfficeName", dbConn)


I declared @OfficeName like this:
Dim OfficeName = New OdbcParameter("@dbOfficeName", OdbcType.Char)

So.... where to go now?

You need to provide a value for the parameter.

LS
 
S

Steve Gerrard

Lloyd said:
m1c said:
I get the following error when I debug my program:
ERROR [42000] [Microsoft][SQL Native Client][SQL Server]Must declare
the scalar variable "@dbOfficeName".

It throws the error on this statement:

SQLOfficeData.ExecuteNonQuery()

Which is defined as:
Dim SQLOfficeData = New OdbcCommand("DECLARE OfficeData CURSOR FOR
SELECT @dbOfficeName FROM Office ORDER BY @dbOfficeName", dbConn)


I declared @OfficeName like this:
Dim OfficeName = New OdbcParameter("@dbOfficeName", OdbcType.Char)

So.... where to go now?

You need to provide a value for the parameter.

LS

And add it to the SQLOfficeData.Parameters collection.
 
M

m1c

I get the following error when I debug my program:
ERROR [42000] [Microsoft][SQL Native Client][SQL Server]Must declare
the scalar variable "@dbOfficeName".
It throws the error on this statement:

Which is defined as:
Dim SQLOfficeData = New OdbcCommand("DECLARE OfficeData CURSOR FOR
SELECT @dbOfficeName FROM Office ORDER BY @dbOfficeName", dbConn)
I declared @OfficeName like this:
Dim OfficeName = New OdbcParameter("@dbOfficeName", OdbcType.Char)
So.... where to go now?

You need to provide a value for the parameter.

LS- Hide quoted text -

- Show quoted text -

Can you supply a code snippet?
 
M

m1c

OfficeName.Value = "MainOffice"


SQLOfficeData.Parameters.Add(OfficeName)

Crap - getting the SOS.
Here's the relevant code:
Dim dbConn = New
System.Data.Odbc.OdbcConnection("Dsn=Election;description=Election;trusted_connection=Yes;app=Microsoft®
Visual Studio® 2008;wsid=M1CVISTA1;database=Election")


Dim CString As String
Dim OfficeName = New OdbcParameter("@dbOfficeName",
OdbcType.Char)
Dim CandidateOfficeName = New
OdbcParameter("@dbCandidateOfficeName", OdbcType.Char)
Dim CandidateName = New OdbcParameter("@dbCandidateName",
OdbcType.Char)
Dim CandidateNumeric = New
OdbcParameter("@dbCandidateNumeric", OdbcType.Int)
Dim CandidateOfficeParty = New
OdbcParameter("@dbCandidateOfficeParty", OdbcType.Char)
Dim CandidatePicture = New
OdbcParameter("@dbCandidatePicture", OdbcType.Char)


Dim CCount As Integer = 0
Dim SQLReturn As Integer = 0

OfficeName.Value = "."
CandidateOfficeName.Value = "."
CandidateName.Value = "."
CandidateNumeric.Value = 0
CandidateOfficeParty.Value = "."
CandidatePicture.Value = "."

dbConn.Open()

Dim SQLOfficeData = New OdbcCommand("DECLARE OfficeData CURSOR
FOR SELECT @dbOfficeName FROM Office ORDER BY @dbOfficeName", dbConn)
Dim SQLOfficeDataOpen = New OdbcCommand("OPEN OfficeData",
dbConn)
Dim SQLOfficeDataFetch = New OdbcCommand("FETCH OfficeData
INTO @dbOfficeName", dbConn)
Dim SQLOfficeDataClose = New OdbcCommand("CLOSE OfficeData",
dbConn)

Dim SQLCandidateData = New OdbcCommand("DECLARE CandidateData
CURSOR FOR SELECT * FROM Candidate ORDER BY CandidateOfficeName",
dbConn)
Dim SQLCandidateDataFetch = New OdbcCommand("FETCH
CandidateData INTO @dbCandidateName, @dbCandidateOfficeName,
@dbCandidateNumeric, @dbCandidateOfficeParty, @dbCandidatePicture",
dbConn)
Dim SQLCandidateDataOpen = New OdbcCommand("OPEN
CandidateData", dbConn)
Dim SQLCandidateDataClose = New OdbcCommand("CLOSE
CandidateData", dbConn)


SQLOfficeData.Parameters.Add(OfficeName)

SQLCandidateData.Parameters.Add(CandidateOfficeName)
SQLCandidateData.Parameters.Add(CandidateName)
SQLCandidateData.Parameters.Add(CandidateNumeric)
SQLCandidateData.Parameters.Add(CandidateOfficeParty)
SQLCandidateData.Parameters.Add(CandidatePicture)

SQLOfficeData.ExecuteNonQuery()<-----ERROR [42000] [Microsoft][SQL
Native Client][SQL Server]Must declare the scalar variable
"@dbOfficeName".
 

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