Must declare the scalar variable "@CheckUser"


Tony M

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) & "(e-mail address removed)" &
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
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

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


Teemu Keiski


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


Omit SqlCmd and set parameter directly with

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