下面显示的代码在监视器上显示标签数据。我需要的是组合“t”中的所有字符并将其插入数据库。下面代码中发生的情况是,每次循环时,它都会将字符打印到 mysql 到不同的条目中。例如:如果十六进制标签长度为 10 个字节,它将在 10 个不同的条目中。我需要以某种方式组合字符并将其插入到 1 个条目中。
我试过把它变成字符串,但是 sprintf() "Query[256]" 的第一个参数必须是字符声明,因此它给了我一个错误。
顺便说一句,下面的代码正在显示从 RFID 阅读器读取的标签。
void CT1121Dlg::DisplayTagData(int cnt,int tag_len,int start_index)
{
MYSQL *pConnection;
MYSQL_RES *pResult=NULL;
MYSQL_ROW Row;
char Query[256];
int a;
int z = 25;
int fields;
pConnection = mysql_init(NULL);
mysql_real_connect(pConnection,"localhost","root","password","test",0,NULL,0);
CString s,s0;
int i,j;
unsigned char t;
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];
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)",t);**
if ( mysql_query(pConnection,Query) == 0 )
{
pResult = mysql_store_result( pConnection );
}
}
AddOprationInfo(s); // print string s on the screen
}
}