SQL SERVE 增删改查

//////////////////////////////////////// 打开数据库BOOL CMystudentsysApp::InitInstance(){if (CoInitialize(NULL)!=0) { AfxMessageBox("初始化COM支持库失败!"); exit(1); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////try{CString strConnect;strConnect.Format("DSN=mystudentsys;");if (m_DB.Open(NULL,false,false,"ODBC;DSN=mystudentsys;UID=Sa;PWD=;")==0){AfxMessageBox("Unable to Connect to the Specified Data Source");return FALSE ;}}catch(CDBException *pE){pE->ReportError();pE->Delete();return FALSE;}AfxEnableControlContainer();///////////////////////////打开表CString sql;sql="SELECT * FROM tb_name";Ctb_name* ss;ss=new Ctb_name(&((CaaApp*)AfxGetApp())->m_db);if (!ss->Open(AFX_DB_USE_DEFAULT_TYPE,sql)){AfxMessageBox(_T("打开表失败"));return;}//////////////////增ss->AddNew();ss->m_name=m_sutentid;ss->Update();ss->Requery();/////////////////////删while (!ss->IsEOF()){if (ss->m_name==m_sutentid){ss->delete();break;}}ss->Update();ss->Requery();//////////////////////////////////改ss->Edit();while (!ss->IsEOF()){if (ss->m_name==m_sutentid){ss->m_name=m_examkind;break;}ss->MoveNext();}//ss->m_name=m_sutentid;ss->Update();ss->Requery();////////////////////////////////////查while (!ss->IsEOF()){if (ss->m_name==m_sutentid){ss->m_name=m_examkind;break;}ss->MoveNext();}ss->Update();ss->Requery();

你可能感兴趣的:(SQL SERVE 增删改查)