SQL Query Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ali Rizwan
    Banned
    Contributor
    • Aug 2007
    • 931

    SQL Query Problem

    I have a database system. And i want to sum the column or filed COST.
    I am using this code

    Code:
    Dim sSQL As String
    
    sSQL = "Select Sum(Cost) from Exp"
    lblST.Caption = Val(sSQL)
    But it is returning null value or 0 to me.

    Whats the problem.

    Using ADODC1
    DATABASE = Access
    Vb6.0
    Xp Sp2

    I have two ADODC's on a form and both have different databases.

    Thanx
  • shaileshb
    New Member
    • Jun 2007
    • 27

    #2
    dim rs as adodb.recordset
    dim strSql as string

    set rs = new adodb.recordset
    strSql = "select Sum(FieldName) From TableName"

    rs.Open strSql, ConnectionObjec t

    lable1.caption = rs.fields(0).va lue

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      Originally posted by Ali Rizwan

      Dim sSQL As String
      sSQL = "Select Sum(Cost) from Exp"
      lblST.Caption = Val(sSQL)
      What do u mean by the above code.
      You are trying to find out value of a string variable. Thats why getting 0.
      You are getting exactly what you have asked for.

      Comment

      Working...