#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename ("EOF","adoEOF") 
我是用这个连的数据库
我有两个数组,CString bh[32],pw[32];我现在想把它存进我建的一个ACCESS数据库的名叫“biaohao”的数据表中,该表一共有两列,第一列列名为biaohao,第 二列列名为password,我要实现的功能是把bh[32],pw[32]这两个数组的内容分别存进数据表的第一列和第二列里,我的代码如下:
         CString bh[32],pw[32];
         CString strSQL;
CString strSmg;
CString bh[32],pw[32];
       int i=0;
       for(i=0;i<32;i++)
      {
         bh[i] = "ddd";
pw[i] = "密码";
      }
int j;
       for(j=0;j<32;j++)
{
strSQL.Format("update biaohao set dianbiaohao='%s'",bh[j]);
strSmg.Format("update biaohao set password='%s'",bh[j]);
try
{
m_pConnection->Execute(_bstr_t(strSQL),NULL,adCmdText);
m_pConnection->Execute(_bstr_t(strSmg),NULL,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}// TODO: Add your control notification handler code here
}
运行无错,可是执行时,  弹出错误提示“biaohao.dianbiaohao不能是零长度的字符串”,请问是怎么回事?
还有我不知道
                  try
{
m_pConnection->Execute(_bstr_t(strSQL),NULL,adCmdText);
m_pConnection->Execute(_bstr_t(strSmg),NULL,adCmdText);
}
这样写可以同时存进两列吗?

解决方案 »

  1.   

    CString   bh[32],这样申明的是一个CString数组,改为
    CString   bh,pw  然后去掉for循环就可以了
      

  2.   

    1.不建议用SQL语句做这件事。
    2.SQL语句错误,应该为
    for(j=0;j <32;j++) 
    {
    strSQL = 
    "Insert Into biaohao values ('" + bh[j] +
    "','" + pw[j] + "')";
    m_pConnection-> Execute(_bstr_t(strSQL),NULL,adCmdText); 
    }
      

  3.   

    strSQL   =   
    "Insert   Into   biaohao   values   ('"   +   bh[j]   + 
    "','"   +   pw[j]   +   "')"; 
    m_pConnection->   Execute(_bstr_t(strSQL),NULL,adCmdText);   
      

  4.   


                      CString   strSQL; 
    CString   strSmg; 
    CString   bh[32],pw[32]; 
                  int   i=0; 
                  for(i=0;i <32;i++) 
                { 
                      bh[i]   =   "ddd"; 
    pw[i]   =   "密码"; 
                } 
    int   j; 
                  for(j=0;j <32;j++) 

    try 

    strSQL   =   
    "Insert   Into   biaohao   values   ('"   +   bh[j]   + 
    "','"   +   pw[j]   +   "')"; 
    // 可以优化为 strSQL   =   "Insert   Into   biaohao   values   ('ddd', '密码')"   
    m_pConnection->   Execute(_bstr_t(strSQL),NULL,adCmdText);   

    catch(_com_error   e) 

    AfxMessageBox(e.Description()); 
    }//   TODO:   Add   your   control   notification   handler   code   here