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.
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 purple line above:
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?
Thanks
Jay
Jay WebsterPosted Feb 1, 2011, 3:05 AM
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?
Jay
Bryian TanPosted Feb 1, 2011, 12:53 AM
Did you check/debug if the response is null? or the response.Image.Results[0] is null?