下午好OleDBDataReader,IndexOutOfRangeException(C#)与SQL COUNT函数
我遇到的代码我工作的一个部分的问题进行检查,以查看是否同名的DataItem中已经存在一个数据库。
下面的代码抛出了一个IndexOutOfRangeException
static int checkExists(String checkIf)
{
String connectionString = "provider=Microsoft.Jet.OLEDB.4.0;data source=" + @"ffmpegDB.mdb";
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
OleDbCommand command = connection.CreateCommand();
try
{
command.CommandText = checkIf;
OleDbDataReader reader = command.ExecuteReader();
reader.Read();
try
{
result = (int)reader["Result"];
}
catch (InvalidOperationException ioe) { }
reader.Close();
connection.Close();
}
catch (FormatException Fe)
{}
return result;
}
..on此线
result = (int)reader["Result"];
该函数如下执行:
if (checkExists("SELECT COUNT(*) AS 'Result' FROM Files WHERE Filename ='"+fileNames[i]+"' AND File_Directory ='"+directories[i]+"'")==0)
{
}
等。
难道这是与OLEDB的问题以及如何处理SQL语句? 也许读者正在从字面上寻找“结果”一栏?
我希望我已经提供了足够的信息。
问候
完美地工作。谢谢 – Ric