我正在开发一个从 OLESQL 服务器读取数据的应用程序。目前我只是在读取数据并将其插入到字符串中。每当我遇到 DBTYPE_WVARCHAR 时,我都会进行一些阅读,我可以使用 myReader.GetString(index),但是发生这种情况时我会崩溃。这是我到目前为止的代码。
OleDbDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
int i =0;
string FullRow = "";
for(i=0;i<myReader.FieldCount;i++)
{
string type=myReader.GetDataTypeName(i);
if ("DBTYPE_I4" == type)
{
FullRow += myReader.GetInt32(i);
}
else if ("Date" == type || "DBDate" == type || "DBTimeStamp" == type)
{
FullRow += myReader.GetDateTime(i).ToString();
}
else if("Char" == type || "LongVarChar" == type || "LongVarWChar" == type || "VarWChar" == type || "WChar" == type ){
FullRow += myReader.GetString(i);
}
else if ("DBTYPE_WVARCHAR" == type)
{
FullRow += myReader.GetString(i); //Crash when this line gets hit
}
else
{
FullRow=FullRow;
}
}
FullRow+=", ";
Console.Write(FullRow);
}