According to the original data in the database is normal, but writing Chinese is gibberish, requires a character encoding conversion? Please the great god teach
My code is as follows:
Add
//Void CAccessToMySQL_APPDlg: : OnBnClickedBtnAdd ()
{
//TODO: add the control notification handler code
The UpdateData (TRUE);
//cstrings m=L "INSERT INTO tdb_goods_brands VALUES ('";
//cstrings 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 into multibyte strings
Cstrings 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);
//cstrings 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 into multibyte strings
If (mysql_query (sock, SQL))
AfxMessageBox (L add failed! "" );
The else
{
FreshList ();
ClearEditCtrl ();
AfxMessageBox (L add success! "" );
}
}
CodePudding user response:
For computer no noise, only the binary bytes; To the human brain is gibberish, GBK: 0 xb0 0 xa1, Unicode - 16 LE: 0 x4a 0 x55, Unicode - 16 BE: 0 x55 0 x4a, utf-8 8-0 x95 xE5 0 0 x8aCodePudding user response:
Install the mysql database server specify the character set encoding of utf-8Create the database also specify utf-8, such as the following statement is executed to create the database available:
The CREATE DATABASE netdb CHARACTER SET 'utf8 COLLATE' utf8_general_ci ';
CodePudding user response:
Cstrings in UNICODE compilation mode for the wide font, so % s can not directly use theCodePudding user response:
Did not set a good character setCodePudding user response:
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);
Try this, into UTF8 encoding,