Hi,
I am trying to use the Bing API to retrieve the first image on whatever search query I enter and then strore the url of the image in MySQL. I am nearly there with it but I am getting an error which I am unable to fix.

Code:
BingService service = new BingService();
SearchRequest request = new SearchRequest(); 
request.AppId = "MYAPPID"; 
request.Query = filePaths[i] + " dvd"; 
request.Sources = new SourceType[] { SourceType.Image }; 
SearchResponse response = service.Search(request); 
OdbcCom = new OdbcCommand("INSERT INTO movies(db_image,db_title,db_quality) values (?,?,?)", OdbcCon); 
OdbcCom.Parameters.Add("@db_image", OdbcType.Text).Value = response.Image.Results[0].MediaUrl; 
OdbcCom.Parameters.Add("@db_title", OdbcType.Text).Value = filePaths[i]; OdbcCom.Parameters.Add("@db_quality", OdbcType.Int).Value = 0; 
OdbcCom.ExecuteNonQuery();
The above code is run about 400 times through all the movie titles.
Although I keep getting the error on the bold line above:
Code:
Object reference not set to an instance of an object.
I am still quite new to C# but I am thinking that it is running through the movies so quickly that the Bing API is unable to keep up with getting the images? Someone can tell me if I am way off base..

Can someone point me in the right direction?

I tested to see if the response was null by doing the following:
Code:
if (response.Image.Results[0].MediaUrl == null)
{
   Console.Writeline("Null");
}
else
{
   OdbcCom.Parameters.Add("@db_image", OdbcType.Text).Value = response.Image.Results[0].MediaUrl;
}
It still throws the error. Maybe I am doing it wrong?

Thanks

Jay