2
Reply

Bing API and MySQL

Jay Webster

Jay Webster

Jan 31 2011 6:45 PM
2.7k

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
 
 

Answers (2)