#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);
}
这样写可以同时存进两列吗?
我是用这个连的数据库
我有两个数组,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);
}
这样写可以同时存进两列吗?
解决方案 »
- Pulic定义的是不是全局变量呢?谢谢!!
- 谁能帮我看看,为什么搜索不到蓝牙设备
- vc的CAD控件
- buyao le
- CDaoDatabase打开access数据库的问题
- 请各位前辈指点:为什么我在A程序中往B程序里添加控件会出错?
- CComboBoxEx类对象,可以使用SelectString函数吗?为什么每次使用都返回-1?代码如下:
- 各位高手见过吗?vc显示一大bug!!!!!!!!!!!!!
- 关于做帮助文件!我用的是HTML Help Workshop1.3,为什么做出来的*.chm文件没有目录部分,是不是要在那里设置呀!
- 弱弱的问个问题:编写服务器端和客户端程序,简单地实现文件传输功能
- 在主线程里调用connect+select方法设置连接超时时,会不会阻塞主线程?
- (求助)如何修改属性页标题?
CString bh,pw 然后去掉for循环就可以了
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);
}
"Insert Into biaohao values ('" + bh[j] +
"','" + pw[j] + "')";
m_pConnection-> Execute(_bstr_t(strSQL),NULL,adCmdText);
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
}