VC++学习经验1

学习经验1

1.SQL中注意insert语句不能和where连用,更新应该用update;

   UPDATE Users_Table

SET UserName='李思'

WHERE id=3

2.注意对异常的控制方式:

  TRY{….}

  CATCH(CException,e){….}

  END_CATCH

3.注意数据记录集CRecordset使用一次open后要马上关闭,否则会出现错误

4.将现有时间插入到SQL中的方法是:

Vc中表示:

CString  strDate=CTime::GetCurrentTime().Format( "%Y-%m-%d %H:%M:%S");

sql.Format((CString)"update LogRecord_Table set logofftime='%s' WHERE id=%d",strDate,maxid);

theApp.m_db.ExecuteSQL(sql);

SQL中提取出时间的方法如下,此方法用于提取完整时间:即年-----秒:

CDBVariant vartime;

TIMESTAMP_STRUCT *ptime=NULL;

if(!rs.IsEOF())

{

       rs.GetFieldValue((short)1,vartime);

       if(vartime.m_dwType!=NULL)

       ptime=vartime.m_pdate;

}

lastlogtime.Format((CString)"%d-%d-%d %d:%d:%d",ptime->year,ptime->month,ptime->day,ptime->hour,ptime->minute,ptime->second);

this->m_ctlMainLastLogTime.SetWindowTextW(lastlogtime);

如果只要求提取出年--日,用如下方法即可:

CString vartime;

if(!rs.IsEOF())

{

       rs.GetFieldValue((short)1,vartime);

}

this->m_ctlMainLastLogTime.SetWindowTextW(vartime);

其中vartime就是年--日方法。

5.注意组合框的使用方法:要先清空列表

//先清空列表

         pCombo->ResetContent();

         //获取当前时间

         CTime tm=CTime::GetTickCount();

         int iYear=tm.GetYear();

         if(bStart==true)

         {

                  for(int i=2000;i<=iYear;i++)

                  {

                          CString temp;

                          temp.Format((CString)"%4d",i);

                          pCombo->AddString(temp);

                  }

         }

         else

         {

                  for(int i=2000;i<=2050;i++)

                  {

                          CString temp;

                          temp.Format((CString)"%4d",i);

                          pCombo->AddString(temp);

                  }

         }

6.获得本机名称和ip地址

WORD wVersionRequested;

        WSADATA wsaData;

        char name[255];

        CString ip;

        PHOSTENT hostinfo;

        wVersionRequested = MAKEWORD( 2, 0 );

 

        if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )

        {

 

              if( gethostname ( name, sizeof(name)) == 0)

              {

                    if((hostinfo = gethostbyname(name)) != NULL)

                    {

                          ip = inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list);

                    }

              }

            

              WSACleanup( );

        }

                  //int n=len(name);

                  CString str(name);

                  //str.Format((CString)"%d",n);

                  //str.Format((CString)"主机名:%s;ip地址:%s",name,ip);

                  this->MessageBox(str);//name里是本机名

7.char*CString之间的转换

   char*CString的转换可用:char* name=”micor”;  CString str(name);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值