Мне нужно обновить базу данных MYSQL.Коды ниже представлены в виде CString.Однако Sprintf принимает тип char.Как мне точно изменить / изменить переменную S, чтобы я мог обновить ее в своей базе данных, используя функцию sprintf.
Спасибо, Джейсон
void CT1121Dlg::DisplayTagData(int cnt,int tag_len,int start_index)
{
MYSQL *pConnection;
MYSQL_RES *pResult=NULL;
MYSQL_ROW Row;
char Query[256];
int fields;
pConnection = mysql_init(NULL);
mysql_real_connect(pConnection,"localhost","root","123","test",0,NULL,0);
CString s,s0;
int i,j;
unsigned char t;
unsigned char t1;
//unsigned char y[] ="";
//string mystring;
//unsigned char y;
for(i = 0; i < cnt; i++)
{
s.Format("NO.%d: ",start_index+i+1);
for(j = 0; j < tag_len; j++)
{
t = IdBuf[i].Ids[j];
//sprintf(Query, "INSERT into t(e) values (%X)",y);
if(t < 0x10)
{
s0.Format("0%X ",t); // if hexa is less than 10 print 0 infront of it
}
else
s0.Format("%X ",t); // else just print the 2 bit hexa decimal
s += s0;
}
sprintf(Query, "INSERT into t(e) values (%X)",s); // nt working
//sprintf(Query, "INSERT into t(e) values (+ %s.c_str() +)",s); // cannot work
if ( mysql_query(pConnection,Query) == 0 )
{
pResult = mysql_store_result( pConnection );
}
AddOprationInfo(s);
}
}