public RecipeDetails dbFindRecepyByID(int ID) { if (con.State != System.Data.ConnectionState.Open) { con.Open(); } RecipeDetails recipeDetails = new RecipeDetails(); SqlCommand cmd = new SqlCommand("SELECT * FROM Recipe WHERE ID=@ID", con); cmd.Parameters.Add("@ID", SqlDbType.Int).Value = ID; SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); recipeDetails.ID = (int)reader.GetValue(0); recipeDetails.Name = reader.GetValue(1).ToString(); recipeDetails.Description = reader.GetValue(2).ToString(); if (reader.GetValue(3) != DBNull.Value) { recipeDetails.Image = (byte[])reader.GetValue(3); } else { recipeDetails.Image = null; } reader.Close(); cmd.Dispose(); con.Close(); return(recipeDetails); }
public List <RecipeDetails> dbLoadRecipe() { if (con.State != System.Data.ConnectionState.Open) { con.Open(); } List <RecipeDetails> listrecipeDetails = new List <RecipeDetails>(); SqlCommand cmd = new SqlCommand("SELECT * FROM Recipe", con); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { RecipeDetails recipe = new RecipeDetails(); recipe.ID = int.Parse((reader.GetValue(0).ToString())); recipe.Name = reader.GetValue(1).ToString(); recipe.Description = reader.GetValue(2).ToString(); if (reader.GetValue(3) != DBNull.Value) { recipe.Image = (byte[])reader.GetValue(3); } else { recipe.Image = null; } listrecipeDetails.Add(recipe); } reader.Close(); cmd.Dispose(); con.Close(); return(listrecipeDetails); }
public void loadRecipe(RecipeDetails recipe) { if (con.State != System.Data.ConnectionState.Open) { con.Open(); } SqlCommand cmd = new SqlCommand("INSERT into [Recipe](ID,Name,Description) VALUES(@ID,@Name,@Description)", con); cmd.Parameters.Add("@ID", System.Data.SqlDbType.VarChar).Value = recipe.ID; cmd.Parameters.Add("@Name", System.Data.SqlDbType.VarChar).Value = recipe.Name; cmd.Parameters.Add("@Description", System.Data.SqlDbType.VarChar).Value = recipe.Description; int test = cmd.ExecuteNonQuery(); cmd.Dispose(); con.Close(); }