Ask Experts Questions for FREE Help !
Ask
    pvsunil's Avatar
    pvsunil Posts: 3, Reputation: 1
    New Member
     
    #1

    Apr 9, 2005, 12:31 AM
    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();
    }
    ===========================================

Check out some similar questions!

Object in nose [ 8 Answers ]

:eek: Does anyone have any advice on getting an objecrt out of a child's nose? One of my son's stuck a bead in his nose and he is too young to blow, so it won't come out. It is not blocking his airway but I don't think it should stay in there. If nothing comes up I think I am taking him to the...

Strange object... [ 4 Answers ]

I'm a 17 year old male and I was recently diagnosed with Ulcerative Colitis. A feew weeks ago I noticed something near my anus... well actually right at the end of my tail bone. It's a round lump and its very hard. I can even move it around, like its just there under my skin attached to nothing....

Automation object [ 1 Answers ]

I wonder if you could help me? I started recentley working in a company. I am at the moment working on some listings of data bases in Access 2000. I was trying to make e customers phone list with the form similar to the one at Northwind Example. Everything went well with the table, form...

UML object oriented design [ 2 Answers ]

Hi Mr/Mrs I want to know more information about UML and object oriented design and how please help me and ntify me about some URL in my issous. Tanks.


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.