Home > Software engineering >  VC MFC in a List Control Control according to the ACCESS database to form content is wrong
VC MFC in a List Control Control according to the ACCESS database to form content is wrong

Time:10-06

I use DAO connection ACCESS database, the initialization List Control controls, read ACCESS database data, the MDB tables in the road to make it displayed in a List Control Control, compile no problem, when performing the Debug an Assertion Failed! Error, a vc + + beginners girl, has been for several days still can't solve agghh ah, ask each altar friend for advice! here is the code I wrote:
First in Roadview. CPP, initialize a List Control controls,
 BOOL CRoadview: : OnInitDialog () 
{
CDialog: : OnInitDialog ();

CFont m_ListFont;

M_ListFont. CreatePointFont (120, "tahoma");

DWORD dwExStyle=m_listroad_view. GetExStyle ();

DwExStyle&=~ LVS_EX_CHECKBOXES;

M_listroad_view. SetFont (& amp; M_ListFont);

M_listroad_view. SetExtendedStyle (dwExStyle | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_ONECLICKA CTIVATE);

The TEXTMETRIC tm;

The CDC * pDC=GetDC ();

PDC - & gt; GetTextMetrics (& amp; Tm);

M_listroad_view. InsertColumn (0, "road number", LVCFMT_CENTER, 90, 0).

M_listroad_view. InsertColumn (1, "road" starting point, LVCFMT_CENTER, 160, 0).

M_listroad_view. InsertColumn (2, "section radius, LVCFMT_CENTER, 120, 0).

M_listroad_view. InsertColumn (3, "road length", LVCFMT_CENTER, 120, 0).

M_listroad_view. InsertColumn (4, "super" route, and LVCFMT_CENTER, 120, 0).

M_listroad_view. InsertColumn (5, "bending direction", LVCFMT_CENTER, 90, 0).

M_listroad_view. InsertColumn (6, "grade", LVCFMT_CENTER, 90, 0).

M_listroad_view. InsertColumn (7, "traffic", LVCFMT_CENTER, 120, 0).

M_listroad_view. InsertColumn (8, "design", LVCFMT_CENTER, 120, 0).

//TODO: Add extra initialization here

return TRUE;

}


The results shown in the figure below


My table is as follows:


Then add the read data code is as follows:
 void CMHCSView: : OnRoadView () 
{


COleVariant var.//the field type

Var. ChangeType (VT_BSTR, NULL);

CListCtrl m_listroad_view;

M_listroad_view. DeleteAllItems ();//to empty table

CDaoDatabase db.

CDaoRecordset RecSet (& amp; Db);

The Open (" data. MDB ");

RecSet. Open (AFX_DAO_USE_DEFAULT_TYPE, "SELECT * FROM road", NULL);

Cstrings STR [9].

int i=0;
Int j=0;

while(! RecSet. IsEOF ())

{

RecSet. GetFieldValue (" ID ", var);

STR [0]=var. IntVal;

RecSet. GetFieldValue (" start ", var);

STR [1]=(LPCSTR) var. PbstrVal;

RecSet. GetFieldValue (" radius ", var);

STR [2]. The Format (" % 10.6 f ", var. DblVal);

RecSet. GetFieldValue (" length ", var);

STR [3]. The Format (" % 10.6 f ", var. DblVal);

RecSet. GetFieldValue (superelevation, var);

STR [4]. The Format (" % 10.6 f ", var. DblVal);

RecSet. GetFieldValue (" direction ", var);

STR [5]=var. IntVal;

RecSet. GetFieldValue (" grade ", var);

STR [6]. The Format (" % 10.6 f ", var. DblVal);

RecSet. GetFieldValue (" volume ", var);

STR [7]=var. IntVal;

RecSet. GetFieldValue (" velocity ", var);

STR [8]. The Format (" % d ", (LPCSTR) var. PbstrVal);

M_listroad_view. InsertItem (m_listroad_view. GetItemCount (), "");

for(j=0; j<=7. J++)

M_listroad_view. SetItemText (I, j, STR [j]);

I=I + 1;

RecSet. MoveNext ();
}
RecSet. Close ();
The Close ();
CRoadview rv;
The rv. DoModal ();

//TODO: Add your command handler code here

}
compile right after implementation, the results are as follows:


What's the problem???

CodePudding user response:

Good girl!
Don't see any problems,
You need in OnRoadView ()/OnInitDialog (), respectively, to make a breakpoint, single step, see which place which statements would crash program?

In addition, OnRoadView () defines how m_listroad_view like global variable name? While it is possible, but not norm, easy to misunderstand,
M_ represents the member variables, you this is a local variable.

CodePudding user response:

Breakpoint debugging will not use this one, look not to understand ah,,,

CodePudding user response:

refer to the second floor nowww response:
breakpoint debugging will not use this one, look not to understand ah,,,

Breaking point, F10 step, behold a code will collapse, is targeted to the analysis,

CodePudding user response:

The Debug mode, open the call stack, look at the function call stack, find the error function call ~ first

CodePudding user response:

Direct the compiler to check the call stack, has been back to your code

CodePudding user response:

Collapsed in the pop-up dialog box, press the corresponding button to enter debugging press Alt + 7 key to view the Call Stack, namely "the Call Stack" from the inside to the following out of from the inner to outer function Call history, double-click a row to the cursor to the Call of the source code or assembly instruction, don't understand when double click on the next line, until we can read ,

CodePudding user response:

reference 1st floor l357630798 response:
good girl!
Don't see any problems,
You need in OnRoadView ()/OnInitDialog (), respectively, to make a breakpoint, single step, see which place which statements would crash program?

In addition, OnRoadView () defines how m_listroad_view like global variable name? nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related