Results 1 to 3 of 3

Thread: select COUNT function

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    24

    select COUNT function

    Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'COUNT'.

    Source Error:


    Line 71: Dim co As String = "SELECT COUNT [f0011AccNumber] FROM [t0011Journal]"
    Line 72: sqlCom1 = New SqlCommand(co, sqlConn)
    Line 73: Dim sqlReader2 As SqlDataReader = sqlCom1.ExecuteReader()
    Line 74: bil = sqlReader2.Read()
    Line 75: bil = bil + 1


    can sombody make correct this code.\ bcoz i got error : invalid column name COUNT.

    COUNT is not a table but function to calculate number of record..

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: select COUNT function

    Code:
    Dim co As String = "SELECT COUNT (f0011AccNumber) FROM t0011Journal"
    Please mark you thread resolved using the Thread Tools as shown

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: select COUNT function

    COUNT is a function and its parameter list must be enclosed parentheses:
    Code:
    SELECT COUNT([f0011AccNumber]) FROM [t0011Journal]
    Also, there's no point specifying a column to COUNT as the number of records is the regardless:
    Code:
    SELECT COUNT(*) FROM [t0011Journal]
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width