我正在使用 SQLAPI++ 将值插入到我的 SQL 数据库中,我正在尝试从国际象棋游戏中提取动作并将其作为字符串插入数据库中的动作表中,就像这样(action_id=1,action_name=e4)。这是我的代码:
int main()
{
SAConnection con;
SACommand cmd;
try
{
con.Connect("test","tester","tester", SA_SQLServer_Client);
cmd.setConnection(&con);
std::ifstream pgnfile("sample.pgn");
pgn::GameCollection games;
pgnfile >> games;
for(pgn::GameCollection::iterator itr=games.begin();itr!=games.end();itr++)
{
pgn::Game game = *itr;
pgn::MoveList move_list=game.moves();
for(pgn::MoveList::iterator itr2=move_list.begin();itr2!=move_list.end();itr2++)
{
pgn::Move move=*itr2;
cmd.setCommandText("insert into actions (action_id,action_name) values (:1,:2)");
cmd.Param(1).setAsLong() = 1;
cmd.Param(2).setAsString() = move.black().str(); // the line that cause the error
}
}
}
}
问题出在这一行:
cmd.Param(2).setAsString() = move.black().str();
它不能从 std::string 转换为 SAString!那么你能告诉我如何进行从 std::string 到 SAString 的转换吗?