473,396 Members | 1,927 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,396 software developers and data experts.

get count fails

TJS

trying to find count of existing email addresses to prevent duplicates but
simple function fails - what am I missing ?

Function DuplicateFound(byVal vEmail as String) As boolean
Dim sqlQuery AS string
Dim cmdSelect AS sqlcommand
sqlQuery = "SELECT Count(*) FROM users WHERE lower(rtrim(ltrim(email))
=@em "
cmdSelect.Parameters.Add( "@em" , vEmail ) '<== error on this line
cmdSelect = New SQLCommand(sqlQuery,con)
con.Open()
if cmdSelect.ExecuteScalar().toString > 0 then :return true : else :
return false:end if
End Function

( con.Open works for update and insert functions )

error msg:

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 248: Dim cmdSelect AS sqlcommand
Line 249: sqlQuery = "SELECT Count(*) FROM Portal_users WHERE
lower(rtrim(ltrim(email)) =@em "
Line 250: cmdSelect.Parameters.Add( "@em" , vEmail )
Line 251: cmdSelect = New SQLCommand(sqlQuery,con)
Line 252: con.Open()
Nov 19 '05 #1
4 1109
You should instantiate your object firstly. After this you can add a
parameter. Just take that line after next line.
--
Thanks,
Yunus Emre ALPÖZEN

"TJS" <no****@here.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...

trying to find count of existing email addresses to prevent duplicates but
simple function fails - what am I missing ?

Function DuplicateFound(byVal vEmail as String) As boolean
Dim sqlQuery AS string
Dim cmdSelect AS sqlcommand
sqlQuery = "SELECT Count(*) FROM users WHERE lower(rtrim(ltrim(email))
=@em "
cmdSelect.Parameters.Add( "@em" , vEmail ) '<== error on this line
cmdSelect = New SQLCommand(sqlQuery,con)
con.Open()
if cmdSelect.ExecuteScalar().toString > 0 then :return true : else :
return false:end if
End Function

( con.Open works for update and insert functions )

error msg:

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:

Line 248: Dim cmdSelect AS sqlcommand
Line 249: sqlQuery = "SELECT Count(*) FROM Portal_users WHERE
lower(rtrim(ltrim(email)) =@em "
Line 250: cmdSelect.Parameters.Add( "@em" , vEmail )
Line 251: cmdSelect = New SQLCommand(sqlQuery,con)
Line 252: con.Open()

Nov 19 '05 #2
TJS
I changed it to
Function DuplicateFound(byVal vEmail as String) As boolean
Dim sqlQuery AS string
Dim cmdSelect AS sqlcommand
sqlQuery = "SELECT Count(*) FROM users WHERE lower(rtrim(ltrim(email)) =
@ em "
cmdSelect = New SQLCommand(sqlQuery,con)
cmdSelect.Parameters.Add( "@em" , vEmail ) '<== error on this line
con.Open()
if cmdSelect.ExecuteScalar() > 0 then :return true : else : return
false:end if
End Function

but I now get error:

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect
syntax near '='.
Nov 19 '05 #3
I think email address is a string based column. you should use = operator
with "'"
Something like this..
sqlQuery = "SELECT Count(*) FROM users WHERE lower(rtrim(ltrim(email)) ='
@ em'
--
Thanks,
Yunus Emre ALPÖZEN

"TJS" <no****@here.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I changed it to
Function DuplicateFound(byVal vEmail as String) As boolean
Dim sqlQuery AS string
Dim cmdSelect AS sqlcommand
sqlQuery = "SELECT Count(*) FROM users WHERE lower(rtrim(ltrim(email)) =
@ em "
cmdSelect = New SQLCommand(sqlQuery,con)
cmdSelect.Parameters.Add( "@em" , vEmail ) '<== error on this line
con.Open()
if cmdSelect.ExecuteScalar() > 0 then :return true : else : return
false:end if
End Function

but I now get error:

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect
syntax near '='.

Nov 19 '05 #4
TJS
hmm ...
that doesn't seem to help either
"Yunus Emre ALPÖZEN" <ye***@msakademik.net> wrote in message
news:Ob**************@tk2msftngp13.phx.gbl...
I think email address is a string based column. you should use = operator
with "'"
Something like this..
sqlQuery = "SELECT Count(*) FROM users WHERE lower(rtrim(ltrim(email)) ='
@ em'
--
Thanks,
Yunus Emre ALPÖZEN

"TJS" <no****@here.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I changed it to
Function DuplicateFound(byVal vEmail as String) As boolean
Dim sqlQuery AS string
Dim cmdSelect AS sqlcommand
sqlQuery = "SELECT Count(*) FROM users WHERE lower(rtrim(ltrim(email))
= @ em "
cmdSelect = New SQLCommand(sqlQuery,con)
cmdSelect.Parameters.Add( "@em" , vEmail ) '<== error on this line
con.Open()
if cmdSelect.ExecuteScalar() > 0 then :return true : else : return
false:end if
End Function

but I now get error:

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect
syntax near '='.


Nov 19 '05 #5

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

Similar topics

4
by: Neil Trigger | last post by:
How would i go about asking the database how many listings there are with the same "Town" field? I want a page that eventually says: "We found XXX listings in ZZZ" Where XXX is the number of...
5
by: gelangov | last post by:
I need to update the columns to blanks if it has Nulls; Most of the time we do not have Nulls and to check that in a 3.2 million table it takes 2 minutes and 45 seconds. (To do select count(*) from...
8
by: Bri | last post by:
Greetings, After making various edits and deletes on aproximately 40,000 records in one table (on the Design Master) syncronization fails with Error 3052 - File Sharing Lock Count Exceeded....
2
by: Sathyaish | last post by:
I have a CSV file like so: "HDR",20060629133932,"9845","9083","0010" 1,"3","000000000690","000007","rsM4hJXR5Ik0O8RWghjtDBlUVAOZq7tO","BAR","0010","","",20.00...
0
by: euniceno1 | last post by:
the problem is to count the letters and sequence from a file. the fist thing of my code is to read file and in the main function i create is to count the characters and sequence by using 2 dimension...
1
by: Vikas | last post by:
Hi all, I am working on a document control database where I have a table "tblControl" containing two columns "DocID" and "SchIssueDate". "DocID" is the key field with text format while...
26
by: Ping | last post by:
Hi, I'm wondering if it is useful to extend the count() method of a list to accept a callable object? What it does should be quite intuitive: count the number of items that the callable returns...
1
by: erebus | last post by:
Consider an Employee table with columns employee id , employee name, salary, department name and department number. We need to find “count” of the aggregate function, say sum of salary, grouped...
1
by: zambia | last post by:
First post so please excuse any Faux Pas's I have an xml file as below <?xml version="1.0"?> <Car> <Type>Ford Sierra</Type> <Service>1 <Date>01/09/2006</Date> <Tyres>OK</Tyres>
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: 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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.