|
-
May 5th, 2010, 09:23 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Count isnt returning anything
i have used this code, but i always get msgbox as 0.
What am i doing wrong.
vb Code:
SqlStr = "SELECT Count(memberid) FROM members WHERE membername Like '*" & Me.TxtFind.Text & "*'"
Using Conn As New OleDb.OleDbConnection(My.Settings.DMSConnectionString)
Using Cmd As New OleDb.OleDbCommand(SqlStr, Conn)
Conn.Open()
MessageBox.Show(Cmd.ExecuteNonQuery().ToString)
Conn.Close()
End Using
End Using
-
May 5th, 2010, 09:32 AM
#2
Re: Count isnt returning anything
ExecuteNonQuery is when you are performing something OTHER than a "SELECT" on a database, aka you are not querying data, you are deleting or updating, or inserting data.
You should be using ExecuteScalar instead, which executes a query that is only supposed to return a single value.
-
May 5th, 2010, 09:40 AM
#3
Thread Starter
Frenzied Member
Re: Count isnt returning anything
before posting it did use executescalar but it isnt working
-
May 5th, 2010, 09:47 AM
#4
Re: Count isnt returning anything
"it isn't working" means nothing to me. You need to explain what happened when you tried. Did you get an error, did you get an undesired result? How can we help you if you provide no information other than "it isn't working"
-
May 5th, 2010, 09:53 AM
#5
Thread Starter
Frenzied Member
Re: Count isnt returning anything
sorry for the improperness
I am getting 0 as the message in the msgbox
-
May 5th, 2010, 10:00 AM
#6
Re: Count isnt returning anything
It is probable that your answer is actually 0 then.
Are you using the correct wildcard type for your database ie sql should be
'%" & Me.TxtFind.Text & "%'"
-
May 5th, 2010, 10:02 AM
#7
Re: Count isnt returning anything
I agree, you probably are just returning no values because no values match, and as Grimfort said, % is used for wildcard SQL matching when you use the LIKE statement.
-
May 5th, 2010, 10:14 AM
#8
Thread Starter
Frenzied Member
Re: Count isnt returning anything
ok % is working. Then when should * be used
-
May 5th, 2010, 10:16 AM
#9
Re: Count isnt returning anything
When selecting all rows of a table in a select statement so you don't have to list every single column name in the given table you are pulling data from.
"Select * from members where memberid = 1234"
-
May 5th, 2010, 10:16 AM
#10
Re: Count isnt returning anything
* is only used in DAO as a wildcard charactor.
--Matt I think he ment in the Like part of the where clause
Sometimes the Programmer
Sometimes the DBA
Mazz1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|