4,011
社区成员
发帖
与我相关
我的任务
分享
//添加
void CAccessToMySQL_APPDlg::OnBnClickedBtnAdd()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(TRUE);
//CString m=L"INSERT INTO tdb_goods_brands VALUES('";
//CString m_sql=m+m_iID+L"','"+m_strBrand+L"')";
//char *my_sql=new char[100];
//WideCharToMultiByte(CP_ACP,0,m_sql.GetBuffer(),-1,my_sql,100,NULL,NULL);//Unicode转换成多字节字符串
CString strCate_id,strBrand_id,strPrice,strIsShow,strIsSaleoff;
GetDlgItemText(IDC_EDIT_CATE,strCate_id);
GetDlgItemText(IDC_EDIT_BRAND_NAME,strBrand_id);
GetDlgItemText(IDC_EDIT_PRICE,strPrice);
GetDlgItemText(IDC_EDIT_IS_SHOW,strIsShow);
GetDlgItemText(IDC_EDIT_IS_SALEOFF,strIsSaleoff);
int iCate_id=_wtoi(strCate_id.GetBuffer());
int iBrand_id=_wtoi(strBrand_id.GetBuffer());
int iIsShow=_wtoi(strIsShow.GetBuffer());
int iIsSaleoff=_wtoi(strIsSaleoff.GetBuffer());
double dPrice=_wtof(strPrice.GetBuffer());
char sql[300];
sprintf_s(sql,"INSERT INTO tdb_goods(goods_name,cate_id,brand_id,goods_price,is_show,is_saleoff) VALUES('%s',%d,%d,%f,%d,%d)",m_strBrand,iCate_id,iBrand_id,dPrice,iIsShow,iIsSaleoff);
//CString sql;
//sql.Format(L"INSERT INTO tdb_goods_brands(brand_name) VALUES('%s');",m_strBrand);
//char *my_sql=new char[100];
//WideCharToMultiByte(CP_ACP,0,sql.GetBuffer(),-1,my_sql,100,NULL,NULL);//Unicode转换成多字节字符串
if(mysql_query(sock,sql))
AfxMessageBox(L"添加失败!");
else
{
FreshList();
ClearEditCtrl();
AfxMessageBox(L"添加成功!");
}
}
sprintf_s(sql,"INSERT INTO tdb_goods(CONVERT(CAST(goods_name AS BINARY) USING 'utf8'),cate_id,brand_id,goods_price,is_show,is_saleoff) VALUES('%s',%d,%d,%f,%d,%d)",m_strBrand,iCate_id,iBrand_id,dPrice,iIsShow,iIsSaleoff);
试下这样,转成UTF8编码,