Home > Software engineering >  Use a column in the database data in VC6.0 problems?
Use a column in the database data in VC6.0 problems?

Time:02-11

I use VC to connect to a database, there is a field Value, there are six field values, 10,20,30,40,50,60. Field data member name is m_Value
The database class for CSectionSet, I define a pointer inside CSectionSet * m_pSet;
Then I want to get the sum of the six field values, displayed in the edit box, edit box ID for IDC_SUM,
How should write code?
I wrote the following code, using a button control:
 void CSectionForm: : OnAvrcul () 
{

If (m_pSet - & gt; IsOpen ()) {
M_pSet - & gt; Close ();
}
M_pSet - & gt; The Open ();
Long a, [10].
Int I=0;
Long b=0;
M_pSet - & gt; MoveFirst ();
while(! M_pSet - & gt; IsEOF ())
{

A [I]=m_pSet - & gt; M_Value;
B +=a [I];
M_pSet - & gt; MoveNext ();
i++;
}
Cstrings c;
C.F ormat (" % d ", b);
SetDlgItemText (IDC_SUM, c);


}

Found displayed is the value of the currently selected item, rather than the sum, I put a [10] changed to a [2], it has six records, should be an error, but he is not an error, I felt there was no walk down recordset, cause there is only a number, so numerical display the selected item, how do I solve?

CodePudding user response:

No one help you, give a little advice

CodePudding user response:

This step you Debug mode order execution, look at the data correct?

CodePudding user response:

According to the description should be each record has a sum (N) of a field, while the application is a N record fields and

CodePudding user response:

refer to the second floor VisualEleven response:
this step you Debug mode order execution, look at the data correct?

Single step debugging, I removed the while loop, in m_pSet - & gt; Directly after MoveNext () statement with b=m_pSet - & gt; M_Value; Then output the value of b, discovery is the first record in the same field values, that is to say under the record set and no roll, (m_Value value at this time or not perform m_pSet - & gt; MoveNext value before (), don't know where the problem is,

CodePudding user response:

reference zgl7903 reply: 3/f
according to the description should be is the sum of each record has a (N) of a field, while the application is N records of a field and
I N record is a field (Value field Value) and ah,
  • Related