public static bool Delete(dbo_TambolClass clsdbo_Tambol) { SqlConnection connection = SAMDataClass.GetConnection(); string deleteProcedure = "[dbo].[TambolDelete]"; SqlCommand deleteCommand = new SqlCommand(deleteProcedure, connection); deleteCommand.CommandType = CommandType.StoredProcedure; if (clsdbo_Tambol.Sub_district != null) { deleteCommand.Parameters.AddWithValue("@OldSub_district", clsdbo_Tambol.Sub_district); } else { deleteCommand.Parameters.AddWithValue("@OldSub_district", DBNull.Value); } if (clsdbo_Tambol.District != null) { deleteCommand.Parameters.AddWithValue("@OldDistrict", clsdbo_Tambol.District); } else { deleteCommand.Parameters.AddWithValue("@OldDistrict", DBNull.Value); } if (clsdbo_Tambol.Province != null) { deleteCommand.Parameters.AddWithValue("@OldProvince", clsdbo_Tambol.Province); } else { deleteCommand.Parameters.AddWithValue("@OldProvince", DBNull.Value); } deleteCommand.Parameters.AddWithValue("@OldID", clsdbo_Tambol.ID); deleteCommand.Parameters.Add("@ReturnValue", System.Data.SqlDbType.Int); deleteCommand.Parameters["@ReturnValue"].Direction = ParameterDirection.Output; try { connection.Open(); deleteCommand.ExecuteNonQuery(); int count = System.Convert.ToInt32(deleteCommand.Parameters["@ReturnValue"].Value); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { return(false); } finally { connection.Close(); } }
public static dbo_TambolClass Select_Record(dbo_TambolClass clsdbo_TambolPara) { logger.Info(System.Web.HttpContext.Current.Request.Cookies["User_ID"].Value + " " + System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString() + " " + System.Reflection.MethodBase.GetCurrentMethod().Name); dbo_TambolClass clsdbo_Tambol = new dbo_TambolClass(); SqlConnection connection = SAMDataClass.GetConnection(); string selectProcedure = "[dbo].[TambolSelect]"; SqlCommand selectCommand = new SqlCommand(selectProcedure, connection); selectCommand.CommandType = CommandType.StoredProcedure; selectCommand.Parameters.AddWithValue("@ID", clsdbo_TambolPara.ID); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { clsdbo_Tambol.Sub_district = reader["Sub_district"] is DBNull ? null : reader["Sub_district"].ToString(); clsdbo_Tambol.District = reader["District"] is DBNull ? null : reader["District"].ToString(); clsdbo_Tambol.Province = reader["Province"] is DBNull ? null : reader["Province"].ToString(); clsdbo_Tambol.ID = System.Convert.ToInt32(reader["ID"]); } else { clsdbo_Tambol = null; } reader.Close(); } catch (SqlException ex) { return(clsdbo_Tambol); } finally { connection.Close(); } return(clsdbo_Tambol); }