Friday, February 24, 2012

get records count

i have this function

it return 0 but the sql statement in the sql query return the right number?how is that

i want to get the number of records any other idea or fix?

PublicFunction UserAlbumPhotoQuota(ByVal userIDAsInteger)AsBoolean

Dim ConnAsNew SqlConnection(ConfigurationManager.ConnectionStrings("Conn").ConnectionString)

Dim strSQLAsString

Dim drAs SqlDataReader

strSQL ="SELECT *, (select count(*) from userAlbumPic where userID=" & userID &") as rec_count from userAlbumPic "

Dim cmdAsNew SqlCommand()cmd =New SqlCommand(strSQL, Conn)

Conn.Open()

dr = cmd.ExecuteReader()

dr.Read()

userQuota = dr("rec_count").ToString

Conn.Close()

EndFunction

PublicFunction UserAlbumPhotoQuota(ByVal userIDAsInteger)AsBoolean
Dim ConnAsNew SqlConnection(ConfigurationManager.ConnectionStrings("Conn").ConnectionString)
Dim strSQLAsString ="select count(*) from userAlbumPic where userID=" & userID
Dim cmdAsNew SqlCommand()cmd =New SqlCommand(strSQL, Conn)
Conn.Open()
userQuota = cmd.ExecuteScalar()
Conn.Close()
EndFunction

Jos

|||

i don't know why it returns 0 ? ?

|||try this:strSQL = "SELECT *, rec_count from userAlbumPic PICSleft join (select userID, count(*) rec_count from userAlbumPic group by userID) usercountson PICS.userID = userCounts.userID"I did not test it but it should work|||

Check whether userID is having the value you are expecting.

Jos

No comments:

Post a Comment