Home > Back-end >  VC, whether the database connection, insert the record
VC, whether the database connection, insert the record

Time:10-01

Great god help!

I don't know the database is connected not,
If I add a record, to the registry for the record to the inside, (the database has been connection can show?
But in the registration page, finally submitted according to operation fails, no record in the registry,

Try
{
M_AdoConn. OnInitADOConn ();//open the database connection
Cstrings SQL="select * from zhuce where USENAME='" + m_strYHM2 +"' ";//query whether user name the same record
M_pRs=m_AdoConn. GetRecordSet (SQL) (_bstr_t);//get record
if(! M_pRs - & gt; AdoEOF)//to determine whether a record is empty
{
AfxMessageBox (" user name already exists ");//not null indicates that user name is
return;
}
The else
{
SQL. The Format (" select ID from zhuce ");//in the registered information query in the table number
M_pRs=m_AdoConn. GetRecordSet (SQL) (_bstr_t);//access number records
If (m_pRs - & gt; AdoEOF)//to determine whether a record is empty
Id=1001;//if the record is empty the id from 1001
The else
{
M_pRs - & gt; MoveLast ();
Id=atoi ((_bstr_t) m_pRs - & gt; GetCollect (" ID "));//the last record student number information
Id +=1;//id from the last student number number plus 1
}
SQL. The Format (" insert into zhuce (USENAME, NAME, SEX, AGE, IDCARD, [PASSD], [PASSDD], \
NUMBER, USETYPE, ID, DATE) values (' % s', '% s',' % s', % d, '% s', \
'% s',' % s', % d, 'VIP', '% s', % d) ", m_strYHM2, m_strXM2, sex, m_age, m_strCARD, m_strMIMA2, \
M_strMIMA22 m_strDHHM, STR, id, nowtime);

M_AdoConn. The ExecuteSQL ((_bstr_t) SQL);//perform the above insert statement
M_AdoConn. ExitConn ();
AfxMessageBox (" registration ");
CDialog: : OnCancel ();
CDMT1 DLG.
DLG. DoModal ();
}
}
The catch (... )
{
AfxMessageBox (" fail ");
return;
}