i want the solution of this

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muddasirmunir
    Contributor
    • Jan 2007
    • 284

    i want the solution of this

    i am using vb6

    i am using sum fuction and bounding a textbox debittxt to it with the followin code

    Code:
     dim debitrs as recordset 
    set debitrs=new recordset
    debitrs.Open "select sum(debit) as debit from salestax", con, adOpenDynamic, adLockOptimistic
    Set totaldebittxt.DataSource = debitrs
    totaldebittxt.DataField = "debit"
    this code works fine, the problem arises only when there is no data in the table , my textbox (debittxt) shows null value obvious if there is no dataits sum is zero but why it donot show me zero(0) in the debittxt text field

    i want the query to show 0 instead of blank if the sum is zero .

    well i had try to make this coding that if the field is blank it is converted to zero

    Code:
     
    If totaldebittxt.Text = "" Then
    totaldebittxt.Text = 0
    End If
    but getting error field not updateable ,

    so what is the best solution for it.
  • Ali Rizwan
    Banned
    Contributor
    • Aug 2007
    • 931

    #2
    Is the debit field an integer or a string/text field??
    The code you are using will update the records automatically. To do such things set debit field to integer or numbers using this the fields if have nothing automatically set to 0.

    Regards
    >> ALI <<

    Comment

    • muddasirmunir
      Contributor
      • Jan 2007
      • 284

      #3
      asalam o alikum ali

      i am using sql server 2000 and the field is numeric.
      the problem only arises only if for example i searchde the record for
      january and if no record of january still enter in the database the field show me blank it means there is no data for january but i want it shoud give me zero instead of blank. becasue i want to do some further calcuation in it and if it is blank it gives me error ahead. so i want it to be zero instead of blank is there any other way?

      Originally posted by Ali Rizwan
      Is the debit field an integer or a string/text field??
      The code you are using will update the records automatically. To do such things set debit field to integer or numbers using this the fields if have nothing automatically set to 0.

      Regards
      >> ALI <<

      Comment

      • Ali Rizwan
        Banned
        Contributor
        • Aug 2007
        • 931

        #4
        Originally posted by muddasirmunir
        asalam o alikum ali

        i am using sql server 2000 and the field is numeric.
        the problem only arises only if for example i searchde the record for
        january and if no record of january still enter in the database the field show me blank it means there is no data for january but i want it shoud give me zero instead of blank. becasue i want to do some further calcuation in it and if it is blank it gives me error ahead. so i want it to be zero instead of blank is there any other way?
        Ok try to use this code. This will update the blank records to zero.

        The code if for adodb.

        Code:
        if [recordset name].fields[fieldindex].value="" then 
         [recordset name].update [fieldindex],0
        end if
        this will update the record if there is a null in it.

        Regards
        >> ALI <<

        Comment

        Working...