public BrandImage GetOneBrandImage(string inBrandPhotoId) { SqlCommand cmd = new SqlCommand(); SqlConnection connection = new SqlConnection(); SqlDataAdapter da = new SqlDataAdapter(); BrandImage bi = new BrandImage(); string connString = ConfigurationManager.ConnectionStrings["WEBAConnectionString"].ConnectionString; connection.ConnectionString = connString; cmd.Connection = connection; da.SelectCommand = cmd; string sqlCommand = " SELECT BrandImageId,Photo,ImageFileName,ImageContentType,ImageContentLength,BrandId FROM BrandImage "; sqlCommand += " WHERE BrandImageId = "; sqlCommand += " @inBrandPhotoId "; cmd.CommandText = sqlCommand; cmd.Parameters.Add("@inBrandPhotoId", SqlDbType.Int).Value = inBrandPhotoId; DataTable productPhotoDataTable = new DataTable(); da.Fill(productPhotoDataTable); DataRow dr = productPhotoDataTable.Rows[0]; bi.Photo = (byte[])dr["Photo"]; bi.BrandImageContentLength = Int32.Parse(dr["ImageContentLength"].ToString()); bi.BrandImageContentType = dr["ImageContentType"].ToString(); bi.BrandImageFileName = dr["ImageFileName"].ToString(); bi.Brand.BrandID = Int32.Parse(dr["BrandId"].ToString()); return(bi); }
public bool DeleteBrandPhoto(string inbrandPhotoId) { int numOfRecordsAffected = 0; string sqlCommand = ""; BrandImage bm = new BrandImage(); string connString = ConfigurationManager.ConnectionStrings["WEBAConnectionString"].ConnectionString; using (SqlConnection cn = new SqlConnection()) { cn.ConnectionString = connString; using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = cn; sqlCommand = " DELETE BrandImage "; sqlCommand += " WHERE BrandImageId = "; sqlCommand += " @inBrandImageId "; cmd.CommandText = sqlCommand; cmd.Parameters.Add("@inBrandImageId", SqlDbType.Int).Value = inbrandPhotoId; cn.Open(); numOfRecordsAffected = cmd.ExecuteNonQuery(); cn.Close(); } //end of using SqlCommand cmd } //end of using SqlConnection cn return((numOfRecordsAffected > 0) ? true : false); }
public bool AddBrandPhoto(BrandImage inBrandPhoto) { int numOfRecordsAffected = 0; SqlCommand command = new SqlCommand(); SqlConnection connection = new SqlConnection(); string connString = ConfigurationManager.ConnectionStrings["WEBAConnectionString"].ConnectionString; connection.ConnectionString = connString; command.Connection = connection; //The SQL Insert statement involves one table, Brand. The record to be created requires //4 fields to be filled, BrandName, BrandImage, BrandContentLength, BrandContentType string sqlCommand = " INSERT INTO BrandImage "; sqlCommand += " (ImageContentLength, ImageContentType, ImageFileName, Photo, BrandId) "; sqlCommand += " VALUES (@inImageContentLength,@inImageContentType,@inImageFileName, @inPhoto, @inBrandId) "; command.CommandText = sqlCommand; //The SQL statement has 4 parameters, these 4 parameters are provided by the properties which belongs to //the inBrand object which is passed in from the calling program (processAddBrand method of ADMAddBrand.aspx) command.Parameters.Add("@inPhoto", SqlDbType.Image, inBrandPhoto.Photo.Length).Value = inBrandPhoto.Photo; command.Parameters.Add("@inImageContentLength", SqlDbType.Int, 100).Value = inBrandPhoto.BrandImageContentLength; command.Parameters.Add("@inImageFileName", SqlDbType.VarChar, 100).Value = inBrandPhoto.BrandImageFileName; command.Parameters.Add("@inImageContentType", SqlDbType.VarChar, 50).Value = inBrandPhoto.BrandImageContentType; command.Parameters.Add("@inBrandId", SqlDbType.Int).Value = inBrandPhoto.BrandID; //Open an active connection connection.Open(); //Send the SQL statement to the database //Send the SQL statement to the database numOfRecordsAffected = command.ExecuteNonQuery(); //Close the database connection. connection.Close(); if (numOfRecordsAffected != 0) { return(true); } else { return(false); } }