473,378 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Must declare the scalar variable "@CheckUser"


vs 2005 - vb .net - web forms - xp pro

Can't figure out why I keep getting the error Must declare the scalar
variable "@CheckUser".
The error happens on SqlDA.Fill(SqlDS). Just trying to make sure EMail
address doesn't exist in database before I insert data.
Connection string and everything else is correct. If I use Dim SQL = "Select
* from Clients where EMail = " & chr(39) & "So**************@msn.com" &
chr(39) it works fine.
Dim parmIfExist As New SqlParameter("@CheckUser", txtEmail.Text)
SQL = "Select * from Clients where EMail = @CheckUser"
SqlCmd.CommandText = SQL
SqlCmd.Connection() = SQLcon
SqlCmd.Connection.Open()
SqlCmd.Parameters.Clear()
SqlCmd.Parameters.Add(parmIfExist)
Dim SqlDA As New SqlDataAdapter(SQL, SQLcon)
Dim SqlDS As New Data.DataSet()
Dim DR As Data.DataRow

SqlDA.Fill(SqlDS) << Error on this line Must declare the scalar variable
"@CheckUser".

If SqlDS.Tables(0).Rows.Count = 0 Then
Do stuff
end if
Thanks
Oct 4 '08 #1
1 8260
Hi,

you don't use the SqlCmd object which has the SqlParameter associated,
instead you pass the SQL directly to the data adapter when it wouldn't have
knowledge of the parameter.

"Dim SqlDA As New SqlDataAdapter(SQL, SQLcon)"

Solution would be:

Construct the SqlDataAdapter with the SqlCmd

OR

Omit SqlCmd and set parameter directly with
SqlDa.SelectCommand.Parameters.Add(...)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://aspadvice.com/blogs/joteke

"Tony M" <To*************@msn.comwrote in message
news:uq**************@TK2MSFTNGP05.phx.gbl...
>
vs 2005 - vb .net - web forms - xp pro

Can't figure out why I keep getting the error Must declare the scalar
variable "@CheckUser".
The error happens on SqlDA.Fill(SqlDS). Just trying to make sure EMail
address doesn't exist in database before I insert data.
Connection string and everything else is correct. If I use Dim SQL =
"Select * from Clients where EMail = " & chr(39) &
"So**************@msn.com" & chr(39) it works fine.
Dim parmIfExist As New SqlParameter("@CheckUser", txtEmail.Text)
SQL = "Select * from Clients where EMail = @CheckUser"
SqlCmd.CommandText = SQL
SqlCmd.Connection() = SQLcon
SqlCmd.Connection.Open()
SqlCmd.Parameters.Clear()
SqlCmd.Parameters.Add(parmIfExist)
Dim SqlDA As New SqlDataAdapter(SQL, SQLcon)
Dim SqlDS As New Data.DataSet()
Dim DR As Data.DataRow

SqlDA.Fill(SqlDS) << Error on this line Must declare the scalar
variable "@CheckUser".

If SqlDS.Tables(0).Rows.Count = 0 Then
Do stuff
end if
Thanks

Oct 5 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Wajih-ur-Rehman | last post by:
I am using the following query: query = "insert into SystemEventsProperties (ID,PName,PValue) values (@id,@pName,@pValue)"; OdbcParameter param1 = new OdbcParameter(); param1.DbType =...
2
by: Boris Zakharin | last post by:
I have the following code upon which I receive the error "Must declare the variable '@job_id'". --Begin Code -- OleDbConnection conDetail = new OleDbConnection("Provider=SQLOLEDB.1;Integrated...
3
by: Ken Adeniji | last post by:
Must declare the scalar variable '@FirstName' ContactGridViewWebForm.aspx <aspqlDataSource RunAt="server" ID="SqlDataSourceContact" ...
1
by: AndrewD | last post by:
when the following SELECT is executed via A cursor to SQL 2005 it works SELECT * FROM LCTRY WHERE LANGUAGE = 'EN' AND CTRY_CODE = :CTRY BUT SELECT * FROM LCTRY WHERE CTRY_CODE = :CTRY...
1
by: Rama Jayapal | last post by:
the following is my code can anybody rectify my problem that i get when running my application "Must declare scalar variable @ID" <asp:GridView ID="GridView1" DataKeyNames="ID" runat="server"...
0
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new...
1
by: adz1809 | last post by:
I'm having a problem with updating a record through a form. Here is the error: Server Error in '/AccoEndUser' Application....
1
by: Mark | last post by:
I am really struggling with this, trying to understand why it doesn't work. I've simplified the code down to the essentials. The GridView displays in ReadOnly mode just fine, Clicking the "edit"...
3
by: krisssgopi | last post by:
Hi Team, Thanks for your effort. When am trying to execute below code it was throwing an exception must declare the variable @uname. Please trigger me where it was going wrong. thanks in advance....
5
by: krisssgopi | last post by:
Hi all, When i run the below code it was throwing an exception must declare the variable @uname. please help me to solve this issue. Try con.Open() Dim param As New...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.