Error in OleDBConnection : Object reference not set to an instance of an object
I am running the following code in .net which connects to MS Access database. It executes when the value of variable I is 1 and when the loop continues and value of I becomes 2 I am getting error "Object reference not set to an instance of an object" in the cmdSearch.CommandText line in the code. . There is no problem with connection string. It successfully retrieves when I = 1. Can anybody help me out what is the problem. Please post with corrected code if anybody can help.
===========================================
for (int I=1; I <= objFolder.Items.Count; I++)
{
System.Data.OleDb.OleDbConnection odbSearch = new System.Data.OleDb.OleDbConnection();
System.Data.OleDb.OleDbCommand cmdSearch = new System.Data.OleDb.OleDbCommand();
odbSearch.ConnectionString = strConn;
cmdSearch.Connection = odbSearch;
item = (Outlook.ContactItem) objFolder.Items.Item(I);
string them = item.Email1Address;
cmdSearch.CommandText = "select * from Outlook_Contacts where FirstName='"+fn.ToString().Trim()+"' and LastName='"+ln.ToString().Trim()+"'";
odbSearch.Open();
OleDbDataReader rdrSearch = cmdSearch.ExecuteReader();
while( rdrSearch.Read())
{
RecordFlag = true;
}
odbSearch.Close();
}
===========================================