public List<SSImage> GetImages(string query)
{
//clear images list
Images.Clear();
if (query == "")
{
return null;
}
//search images in database
try
{
string connStr = ConfigurationManager.ConnectionStrings["fuddleConnectionString"].ConnectionString;
conn = new SqlConnection(connStr);
cmd = new SqlCommand("SELECT Image_id,Image_thumbHeight,Image_thumbWidth,Image_title FROM [Image_table] WHERE Image_desc like '%" + query + "%' OR Image_title like '%" + query + "%' OR Image_filename like '%" + query + "%'", conn);
conn.Open();
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//get the id
int id = ((int)rdr["Image_id"]);
//get the width of thumb
int width = ((int)rdr["Image_thumbWidth"]);
//get the height of thumb
int height = ((int)rdr["Image_thumbHeight"]);
//get the title
string title = ((string)rdr["Image_title"]);
//add to images list
SSImage newImage = new SSImage { id = id, width = width, height = height, title=title };
Images.Add(newImage);
}
if (rdr != null)
rdr.Close();
}
finally
{
conn.Close();
conn.Dispose();
}
//return the json data
return Images;
}