zoukankan      html  css  js  c++  java
  • sql CString 转int 问题

     1 void LendAddEq::OnSureAddLend()
     2 {
     3     // TODO:  在此添加控件通知处理程序代码
     4     CString id, e_name,p_name,l_date,r_date;
     5 
     6     lend_flag = "lending";
     7 
     8     BOOL In = FALSE;
     9 
    10     CString sum_count;
    11     CString c_name;
    12     int count=0;
    13 
    14     CString q;
    15     
    16 
    17 
    18     GetDlgItemText(IDC_EDIT1, id);
    19     GetDlgItemText(IDC_EDIT2, e_name);
    20     GetDlgItemText(IDC_EDIT4, p_name);
    21     GetDlgItemText(IDC_EDIT5, l_date);
    22     GetDlgItemText(IDC_EDIT6, r_date);
    23 
    24     rs.Open(CRecordset::forwardOnly, _T("SELECT * FROM equipment_table order by id Desc"));
    25     while (!rs.IsEOF())
    26     {
    27         
    28         rs.GetFieldValue(L"equipment_name", c_name);
    29         //AfxMessageBox(c_name);
    30         if (c_name == e_name)
    31         {
    32             //if ()借走数量
    33             rs.GetFieldValue(L"sum_count", sum_count);
    34             AfxMessageBox(sum_count);
    35             count = _ttoi(sum_count);
    36             //AfxMessageBox(count);
    37             if (count - 1 > 0)
    38             {
    39                 In = TRUE;
    40                 count =count - 1;
    41                 q.Format(L"%d", count);
    42                 AfxMessageBox(q);
    43                 break;
    44             }
    45             
    46         }
    47         rs.MoveNext();
    48     }
    49     rs.Close();
    50     if (In)
    51     {
    52         CString sql1;
    53         sql1.Format(L"update equipment_table set count='%d' where equipment_name='%s'", count, c_name);
    54         db.ExecuteSQL(sql1);
    55 
    56         CString sql;
    57         sql.Format(_T("insert into lend_table (id, eq_name,people_name,flag,lend_date,return_date) values ('%s','%s','%s','%s','%s','%s')"), id, e_name, p_name, lend_flag, l_date, r_date);
    58         db.ExecuteSQL(sql);
    59 
    60         AfxMessageBox(L"添加成功");
    61         EndDialog(true);
    62     }
    63     else
    64     {
    65         MessageBox(L"实验室没有该设备!");
    66     }
    67 }

    rs.GetFieldValue(L"sum_count", sum_count);    //读取数据
    //AfxMessageBox(sum_count);
    count = _ttoi(sum_count);       //CString转换int
    //AfxMessageBox(count);     

    q.Format(L"%d", count);   //int再转为CString 

    终于解决了我更新数据库的问题

  • 相关阅读:
    MySQL8.0.x免安装配置
    Java中锁的实现与内存语义
    并发中的volatile
    「LOJ #2163」「POI2011」Tree Rotations
    「CodeChef REBXOR」Nikitosh and xor
    「Codeforces 429D」Destiny
    「Luogu P2042」「NOI2005」维护数列
    「SPOJ SEQ」 Recursive Sequence
    「GCJ 2008 Round 1A C」numbers
    「LOJ #6016」崂山白花蛇草水
  • 原文地址:https://www.cnblogs.com/newworldcom/p/3978878.html
Copyright © 2011-2022 走看看