为什么MS访问odbc返回数字但C#中没有字符串?

Dea*_*ean 14 c# mono ms-access unity-game-engine

我正在使用ODBC连接从Windows 7上的Unity3D环境(Mono.net)中的Access文件(.mdb)获取数据,并且连接,断开连接和请求发生时没有任何错误.

但是当我读到我得到的数据时,我只收到数据库中的数字.它可以是整数或浮点数.但是当我尝试获取字符串时,它总是返回一个空字符串.

以下是我在DataBaseHandler类中用于执行请求(提取)的内容:

public ArrayList Execute(string req)
{
ArrayList output = new ArrayList();

[...]

cmd = new OdbcCommand(req);
cmd.Connection = accessConnection;

OdbcDataReader reader = cmd.ExecuteReader();
while (reader.Read()) {
    String[] row = new String[reader.FieldCount];

    for (int i=0; i<reader.FieldCount; i++) {
        if (!reader.IsDBNull(i)) { // Added if for Visual Studio
            // Getting empties strings, but work fine with numbers
            row[i] = reader.GetValue(i).ToString(); 
            // I was using GetString before, but didn't work with Visual Studio
        }
    }

    output.Add( row );
}

[...]
return output;
}
Run Code Online (Sandbox Code Playgroud)

这就是我为测试请求而执行的操作:

ArrayList data = db.Execute("SELECT * FROM Materials");

foreach (String[] row in data) {
    string line = "";
    foreach (String s in row) {
        line += s + " - ";
    }
    Debug.Log(line); // Logging in Unity3D console
}
Run Code Online (Sandbox Code Playgroud)

我得到了:

1234 - 23.1 - - -
5678 - 12.9 - - -
Run Code Online (Sandbox Code Playgroud)

代替 :

1234 - 23.1 - A string - Another string -
5678 - 12.9 - Hello - World -
Run Code Online (Sandbox Code Playgroud)

为什么我只获得数字而没有字符串,我该如何纠正它?

编辑:它可以与Visual Studio 12和Windows 7一起使用,并且我必须进行的编辑才能使它与Visual Studio一起工作,但我的Unity程序没有任何改进.

小智 0

我认为您在从 Access 数据库读取数据时使用 DataSet 而不是 \xd9\x90DataReader !

\n