数据库里有个字段Code为char类型,程序里获取得到文件名为strName,(CString类型的)
为什么下面这句话出错呢
m_pRecordset->putcollect(_variant_t("Code"),_variant_t(strName));我用getbuffer转换一下也不行
char *p;
p=strName.GetBuffer(strName.GetLength());
strName.ReleaseBuffer;
m_pRecordset->putcollect(_variant_t("Code"),p);
为什么下面这句话出错呢
m_pRecordset->putcollect(_variant_t("Code"),_variant_t(strName));我用getbuffer转换一下也不行
char *p;
p=strName.GetBuffer(strName.GetLength());
strName.ReleaseBuffer;
m_pRecordset->putcollect(_variant_t("Code"),p);
另外GetBuffer的用法有错误,应该在使用指针之后再ReleaseBuffer()。而且GetBuffer里传入0就可以了。
CString str(buf);
即可
m_name是CString的
再发一次好了:
m_pRecordset->PutCollect("姓名",_bstr_t(m_name));
你确定_bstr_t((LPCSTR) strName)不行??
是不行
m_pRecordset->putcollect(_variant_t("Code"),(LPCSTR)(strName));
或者
m_pRecordset->putcollect(_variant_t("Code"),_bstr_t((LPCSTR)(strName)));
都不行字段名是正确的,我想就是CString存入char类型出错了,总不会是其他错误吧
_variant_t varName = m_pRecordset->GetCollect(_variant_t(_T("Code")));
SetDlgItemText(IDC_NAME,strName)
读取显示是没问题的,就是输入的时候出错了
课程设计的时候给我很大帮助的网站。不知能否帮楼主找到灵感
同样的代码在输入字段为nvarchar类型的字段的时候就能正常输入,char类型的该怎么转啊
m_pRecordset->putcollect(_variant_t("Code"),00);
字符串该怎么入呢
char buf[100]="";
for(int i=0;i<strName.GetLength();i++)
buf[i]=strName.GetAt(i);
CString strName = file.GetFileTitle();//比如"55.ico"
m_pRecordset->putcollect(_variant_t("Code"),_variant_t(strName));
由于Code是char类型的,所以一直报错
我把strName存入varchar类型的就可以
请教大家,得到文件名strName后怎么把它存入char类型里啊
你百度下有很清楚的说明 或者直接去看vc头文件库