By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,529 Members | 864 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,529 IT Pros & Developers. It's quick & easy.

i want the solution of this

100+
P: 284
i am using vb6

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

Expand|Select|Wrap|Line Numbers
  1.  dim debitrs as recordset 
  2. set debitrs=new recordset
  3. debitrs.Open "select sum(debit) as debit from salestax", con, adOpenDynamic, adLockOptimistic
  4. Set totaldebittxt.DataSource = debitrs
  5. totaldebittxt.DataField = "debit"
  6.  
  7.  
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

Expand|Select|Wrap|Line Numbers
  1.  
  2. If totaldebittxt.Text = "" Then
  3. totaldebittxt.Text = 0
  4. End If
  5.  
  6.  
but getting error field not updateable ,

so what is the best solution for it.
Jun 6 '08 #1
Share this Question
Share on Google+
3 Replies


Ali Rizwan
100+
P: 927
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 <<
Jun 6 '08 #2

100+
P: 284
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?

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 <<
Jun 6 '08 #3

Ali Rizwan
100+
P: 927
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.

Expand|Select|Wrap|Line Numbers
  1. if [recordset name].fields[fieldindex].value="" then 
  2.  [recordset name].update [fieldindex],0
  3. end if
this will update the record if there is a null in it.

Regards
>> ALI <<
Jun 7 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.