下面顯示的代碼在顯示器上顯示標籤數據。我需要的是將所有字符組合到「t」中並將其插入到數據庫中。在下面的代碼中會發生什麼,每當它循環時,它會將字符輸入到mysql中以輸入不同的條目。例如:如果十六進制標籤的長度是10個字節長,它將在10個不同的條目中。我需要以某種方式組合字符並將其插入1條目中。將字符組合到數據庫中
我已經試過把它變成字符串,但sprintf()「Query [256]」的第一個參數需要是字符聲明,因此它給了我一個錯誤。
Btw下面的代碼顯示正在讀取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
}
}
我建議你改變你的密碼,現在你已經公佈在互聯網上。特別是如果你在別處使用相同的密碼。 – bdonlan 2012-03-11 09:34:56