如何使用clr / c ++从数据库中获取一个int并将其转换为system :: int

问题描述 投票:0回答:1

我遇到的问题是我想从数据库中读取一个整数值,但是我需要进行CLR转换,因为它需要从我的数据库中追加到另一个整数中,然后再写回到数据库中。我已经在这个项目中完成了字符串转换,所以我看不到为什么我不能做整数。

我已经拥有的代码:

try
        {
            OleDbDataReader^ reader = testData.openData(fieldEntity, field, tableName);
            while (reader->Read())
            {
                string userName, passWord;
                String^ username = reader["username"]->ToString();
                String^ password = reader["password"]->ToString();
                stringConversion(username, userName);
                stringConversion(password, passWord);
                /* this means that i will have the System::String^ as system::string and I want the same as this but for integers not strings*/
            }
         }

stringConversion

void stringConversion(String ^ s, string& os)
{
    using namespace Runtime::InteropServices;
    const char* chars =
        (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
    os = chars;
    Marshal::FreeHGlobal(IntPtr((void*)chars));
}

编辑:我的catch语句丢失了,但是不需要在那里。

sql c++-cli
1个回答
0
投票

我已经找到了解决这个问题的方法,它实际上是很基本的。

[当处理一个对象时,我可以像使用普通变量一样进行转换。

© www.soinside.com 2019 - 2024. All rights reserved.