[問題] VC++存資料進MySQL如何使用VC++中的變數

作者: chingyue (ChingYue)   2017-04-19 11:55:21
開發平台(Platform): (Ex: Win10, Linux, ...)
Win7
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
VC++ 2013(WIN32 API)
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
MySQL C API
問題(Question):
各位前輩好
小弟現在寫了一隻程式
功能是先讀取資料夾內的檔案
再把檔案名子存入資料庫
可是現在問題是
我不知道該如何在mysql_query()中加入VC++內的變數
小弟嘗試了3種寫法都會出現錯誤
1:
mysql_query(&myCont, "insert into ccc values (NULL, '%s');",dir);
會在dir這邊出現"Error:函式呼叫中的引數太多"
2:
mysql_query(&myCont, "insert into ccc values (NULL, 'dir');");
這樣存到資料庫內都全部都是dir而不是變數內的值
3:
mysql_query(&myCont, "insert into ccc values (NULL, "dir");");
會在dir這邊出現" Error:必須是')' "
麻煩各位前輩指導小弟
謝謝!
程式碼網址(ideone):http://ideone.com/sM42ts
程式碼圖片:http://i.imgur.com/71deIkV.jpg
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <windows.h>
#include <stdio.h>
#include <mysql.h>
#include <string>
#include <iostream>
void main()
{
char InputPath[] = "D:\\tttrrr\\";
//放要讀取檔案的資料夾路徑到InputPath字串裡
char szDir[MAX_PATH];
char dir[MAX_PATH];
WIN32_FIND_DATA FileData;
HANDLE hList;
//
作者: LPH66 (-6.2598534e+18f)   2017-04-19 11:58:00
關鍵字: sprintf

Links booklink

Contact Us: admin [ a t ] ucptt.com