public static DataTable SelectAll() { SqlConnection connection = MarriageData.GetConnection(); string selectStatement = "SELECT " + " [User Name] = [Login].[User_Name] " + " ,[Password] = [Login].[Password] " + "FROM " + " [Login] " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.CommandType = CommandType.Text; DataTable dt = new DataTable(); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(); if (reader.HasRows) { dt.Load(reader); } reader.Close(); } catch (SqlException) { return(dt); } finally { connection.Close(); } return(dt); }
public static List <MarriageRec_Dispensation_Type26> List() { List <MarriageRec_Dispensation_Type26> MarriageRec_Dispensation_TypeList = new List <MarriageRec_Dispensation_Type26>(); SqlConnection connection = MarriageData.GetConnection(); string selectStatement = "SELECT " + " [Dispensation_Type_ID] " + "FROM " + " [Dispensation_Type] " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(); MarriageRec_Dispensation_Type26 clsMarriageRec_Dispensation_Type = new MarriageRec_Dispensation_Type26(); while (reader.Read()) { clsMarriageRec_Dispensation_Type = new MarriageRec_Dispensation_Type26(); clsMarriageRec_Dispensation_Type.Dispensation_Type_ID = System.Convert.ToInt16(reader["Dispensation_Type_ID"]); MarriageRec_Dispensation_TypeList.Add(clsMarriageRec_Dispensation_Type); } reader.Close(); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } return(MarriageRec_Dispensation_TypeList); }
public static List <MarriageRec_Catholic_Party29> List() { List <MarriageRec_Catholic_Party29> MarriageRec_Catholic_PartyList = new List <MarriageRec_Catholic_Party29>(); SqlConnection connection = MarriageData.GetConnection(); string selectStatement = "SELECT " + " [Catholic_Party_ID] " + "FROM " + " [Catholic_Party] " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(); MarriageRec_Catholic_Party29 clsMarriageRec_Catholic_Party = new MarriageRec_Catholic_Party29(); while (reader.Read()) { clsMarriageRec_Catholic_Party = new MarriageRec_Catholic_Party29(); clsMarriageRec_Catholic_Party.Catholic_Party_ID = System.Convert.ToInt16(reader["Catholic_Party_ID"]); MarriageRec_Catholic_PartyList.Add(clsMarriageRec_Catholic_Party); } reader.Close(); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } return(MarriageRec_Catholic_PartyList); }
public static DataTable SelectAll() { SqlConnection connection = MarriageData.GetConnection(); string selectStatement = "SELECT " + " [Catholic Party I D] = [Catholic_Party].[Catholic_Party_ID] " + " ,[Catholic Party Category] = [Catholic_Party].[Catholic_Party_Category] " + "FROM " + " [Catholic_Party] " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.CommandType = CommandType.Text; DataTable dt = new DataTable(); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(); if (reader.HasRows) { dt.Load(reader); } reader.Close(); } catch (SqlException) { return(dt); } finally { connection.Close(); } return(dt); }
public static List <MarriageRec_Groom21> List() { List <MarriageRec_Groom21> MarriageRec_GroomList = new List <MarriageRec_Groom21>(); SqlConnection connection = MarriageData.GetConnection(); string selectStatement = "SELECT " + " [Groom_ID] " + "FROM " + " [Groom] " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(); MarriageRec_Groom21 clsMarriageRec_Groom = new MarriageRec_Groom21(); while (reader.Read()) { clsMarriageRec_Groom = new MarriageRec_Groom21(); clsMarriageRec_Groom.Groom_ID = System.Convert.ToInt32(reader["Groom_ID"]); MarriageRec_GroomList.Add(clsMarriageRec_Groom); } reader.Close(); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } return(MarriageRec_GroomList); }
public static bool Update(Bride oldBride, Bride newBride) { SqlConnection connection = MarriageData.GetConnection(); string updateStatement = "UPDATE " + " [Bride] " + "SET " + " [Bride_First_Name] = @NewBride_First_Name " + " ,[Bride_Middle_Int] = @NewBride_Middle_Int " + " ,[Bride_Last_Name] = @NewBride_Last_Name " + "WHERE " + " [Bride_ID] = @OldBride_ID " + " AND [Bride_First_Name] = @OldBride_First_Name " + " AND [Bride_Middle_Int] = @OldBride_Middle_Int " + " AND [Bride_Last_Name] = @OldBride_Last_Name " + ""; SqlCommand updateCommand = new SqlCommand(updateStatement, connection); updateCommand.CommandType = CommandType.Text; updateCommand.Parameters.AddWithValue("@NewBride_First_Name", newBride.Bride_First_Name); updateCommand.Parameters.AddWithValue("@NewBride_Middle_Int", newBride.Bride_Middle_Int); updateCommand.Parameters.AddWithValue("@NewBride_Last_Name", newBride.Bride_Last_Name); updateCommand.Parameters.AddWithValue("@OldBride_ID", oldBride.Bride_ID); updateCommand.Parameters.AddWithValue("@OldBride_First_Name", oldBride.Bride_First_Name); updateCommand.Parameters.AddWithValue("@OldBride_Middle_Int", oldBride.Bride_Middle_Int); updateCommand.Parameters.AddWithValue("@OldBride_Last_Name", oldBride.Bride_Last_Name); try { connection.Open(); int count = updateCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public static Bride Select_Record(Bride clsBridePara) { Bride clsBride = new Bride(); SqlConnection connection = MarriageData.GetConnection(); string selectStatement = "SELECT " + " [Bride_ID] " + " ,[Bride_First_Name] " + " ,[Bride_Middle_Int] " + " ,[Bride_Last_Name] " + "FROM " + " [Bride] " + "WHERE " + " [Bride_ID] = @Bride_ID " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.CommandType = CommandType.Text; selectCommand.Parameters.AddWithValue("@Bride_ID", clsBridePara.Bride_ID); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { clsBride.Bride_ID = System.Convert.ToInt32(reader["Bride_ID"]); clsBride.Bride_First_Name = System.Convert.ToString(reader["Bride_First_Name"]); clsBride.Bride_Middle_Int = System.Convert.ToString(reader["Bride_Middle_Int"]); clsBride.Bride_Last_Name = System.Convert.ToString(reader["Bride_Last_Name"]); } else { clsBride = null; } reader.Close(); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } return(clsBride); }
public static bool Add(Bride clsBride) { SqlConnection connection = MarriageData.GetConnection(); string insertStatement = "INSERT " + " [Bride] " + " ( " + " [Bride_First_Name] " + " ,[Bride_Middle_Int] " + " ,[Bride_Last_Name] " + " ) " + "VALUES " + " ( " + " @Bride_First_Name " + " ,@Bride_Middle_Int " + " ,@Bride_Last_Name " + " ) " + ""; SqlCommand insertCommand = new SqlCommand(insertStatement, connection); insertCommand.CommandType = CommandType.Text; insertCommand.Parameters.AddWithValue("@Bride_First_Name", clsBride.Bride_First_Name); insertCommand.Parameters.AddWithValue("@Bride_Middle_Int", clsBride.Bride_Middle_Int); insertCommand.Parameters.AddWithValue("@Bride_Last_Name", clsBride.Bride_Last_Name); try { connection.Open(); int count = insertCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public static bool Update(Parish oldParish, Parish newParish) { SqlConnection connection = MarriageData.GetConnection(); string updateStatement = "UPDATE " + " [Parish] " + "SET " + " [ParishName] = @NewParishName " + " ,[KCSJDiocese] = @NewKCSJDiocese " + "WHERE " + " [Parish_ID] = @OldParish_ID " + " AND [ParishName] = @OldParishName " + " AND [KCSJDiocese] = @OldKCSJDiocese " + ""; SqlCommand updateCommand = new SqlCommand(updateStatement, connection); updateCommand.CommandType = CommandType.Text; updateCommand.Parameters.AddWithValue("@NewParishName", newParish.ParishName); updateCommand.Parameters.AddWithValue("@NewKCSJDiocese", newParish.KCSJDiocese); updateCommand.Parameters.AddWithValue("@OldParish_ID", oldParish.Parish_ID); updateCommand.Parameters.AddWithValue("@OldParishName", oldParish.ParishName); updateCommand.Parameters.AddWithValue("@OldKCSJDiocese", oldParish.KCSJDiocese); try { connection.Open(); int count = updateCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public static Parish Select_Record(Parish clsParishPara) { Parish clsParish = new Parish(); SqlConnection connection = MarriageData.GetConnection(); string selectStatement = "SELECT " + " [Parish_ID] " + " ,[ParishName] " + " ,[KCSJDiocese] " + "FROM " + " [Parish] " + "WHERE " + " [Parish_ID] = @Parish_ID " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.CommandType = CommandType.Text; selectCommand.Parameters.AddWithValue("@Parish_ID", clsParishPara.Parish_ID); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { clsParish.Parish_ID = System.Convert.ToInt16(reader["Parish_ID"]); clsParish.ParishName = System.Convert.ToString(reader["ParishName"]); clsParish.KCSJDiocese = System.Convert.ToBoolean(reader["KCSJDiocese"]); } else { clsParish = null; } reader.Close(); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } return(clsParish); }
public static Log Select_Record(Log clsLogPara) { Log clsLog = new Log(); SqlConnection connection = MarriageData.GetConnection(); string selectStatement = "SELECT " + " [Log_ID] " + " ,[User_Name] " + " ,[Note] " + "FROM " + " [Log] " + "WHERE " + " [Log_ID] = @Log_ID " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.CommandType = CommandType.Text; selectCommand.Parameters.AddWithValue("@Log_ID", clsLogPara.Log_ID); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { clsLog.Log_ID = System.Convert.ToInt32(reader["Log_ID"]); clsLog.User_Name = System.Convert.ToString(reader["User_Name"]); clsLog.Note = System.Convert.ToString(reader["Note"]); } else { clsLog = null; } reader.Close(); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } return(clsLog); }
public static bool Update(Log oldLog, Log newLog) { SqlConnection connection = MarriageData.GetConnection(); string updateStatement = "UPDATE " + " [Log] " + "SET " + " [User_Name] = @NewUser_Name " + " ,[Note] = @NewNote " + "WHERE " + " [Log_ID] = @OldLog_ID " + " AND [User_Name] = @OldUser_Name " + " AND [Note] = @OldNote " + ""; SqlCommand updateCommand = new SqlCommand(updateStatement, connection); updateCommand.CommandType = CommandType.Text; updateCommand.Parameters.AddWithValue("@NewUser_Name", newLog.User_Name); updateCommand.Parameters.AddWithValue("@NewNote", newLog.Note); updateCommand.Parameters.AddWithValue("@OldLog_ID", oldLog.Log_ID); updateCommand.Parameters.AddWithValue("@OldUser_Name", oldLog.User_Name); updateCommand.Parameters.AddWithValue("@OldNote", oldLog.Note); try { connection.Open(); int count = updateCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public static Catholic_Party Select_Record(Catholic_Party clsCatholic_PartyPara) { Catholic_Party clsCatholic_Party = new Catholic_Party(); SqlConnection connection = MarriageData.GetConnection(); string selectStatement = "SELECT " + " [Catholic_Party_ID] " + " ,[Catholic_Party_Category] " + "FROM " + " [Catholic_Party] " + "WHERE " + " [Catholic_Party_ID] = @Catholic_Party_ID " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.CommandType = CommandType.Text; selectCommand.Parameters.AddWithValue("@Catholic_Party_ID", clsCatholic_PartyPara.Catholic_Party_ID); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { clsCatholic_Party.Catholic_Party_ID = System.Convert.ToInt16(reader["Catholic_Party_ID"]); clsCatholic_Party.Catholic_Party_Category = System.Convert.ToString(reader["Catholic_Party_Category"]); } else { clsCatholic_Party = null; } reader.Close(); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } return(clsCatholic_Party); }
public static Login Select_Record(Login clsLoginPara) { Login clsLogin = new Login(); SqlConnection connection = MarriageData.GetConnection(); string selectStatement = "SELECT " + " [User_Name] " + " ,[Password] " + "FROM " + " [Login] " + "WHERE " + " [User_Name] = @User_Name " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.CommandType = CommandType.Text; selectCommand.Parameters.AddWithValue("@User_Name", clsLoginPara.User_Name); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { clsLogin.User_Name = System.Convert.ToString(reader["User_Name"]); clsLogin.Password = System.Convert.ToString(reader["Password"]); } else { clsLogin = null; } reader.Close(); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } return(clsLogin); }
public static Dispensation Select_Record(Dispensation clsDispensationPara) { Dispensation clsDispensation = new Dispensation(); SqlConnection connection = MarriageData.GetConnection(); string selectStatement = "SELECT " + " [Dispensation_ID] " + " ,[Dispensation_Category] " + "FROM " + " [Dispensation] " + "WHERE " + " [Dispensation_ID] = @Dispensation_ID " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.CommandType = CommandType.Text; selectCommand.Parameters.AddWithValue("@Dispensation_ID", clsDispensationPara.Dispensation_ID); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow); if (reader.Read()) { clsDispensation.Dispensation_ID = System.Convert.ToInt32(reader["Dispensation_ID"]); clsDispensation.Dispensation_Category = System.Convert.ToString(reader["Dispensation_Category"]); } else { clsDispensation = null; } reader.Close(); } catch (SqlException ex) { throw ex; } finally { connection.Close(); } return(clsDispensation); }
public static bool Add(Log clsLog) { SqlConnection connection = MarriageData.GetConnection(); string insertStatement = "INSERT " + " [Log] " + " ( " + " [User_Name] " + " ,[Note] " + " ) " + "VALUES " + " ( " + " @User_Name " + " ,@Note " + " ) " + ""; SqlCommand insertCommand = new SqlCommand(insertStatement, connection); insertCommand.CommandType = CommandType.Text; insertCommand.Parameters.AddWithValue("@User_Name", clsLog.User_Name); insertCommand.Parameters.AddWithValue("@Note", clsLog.Note); try { connection.Open(); int count = insertCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public static bool Update(Catholic_Party oldCatholic_Party, Catholic_Party newCatholic_Party) { SqlConnection connection = MarriageData.GetConnection(); string updateStatement = "UPDATE " + " [Catholic_Party] " + "SET " + " [Catholic_Party_Category] = @NewCatholic_Party_Category " + "WHERE " + " [Catholic_Party_ID] = @OldCatholic_Party_ID " + " AND [Catholic_Party_Category] = @OldCatholic_Party_Category " + ""; SqlCommand updateCommand = new SqlCommand(updateStatement, connection); updateCommand.CommandType = CommandType.Text; updateCommand.Parameters.AddWithValue("@NewCatholic_Party_Category", newCatholic_Party.Catholic_Party_Category); updateCommand.Parameters.AddWithValue("@OldCatholic_Party_ID", oldCatholic_Party.Catholic_Party_ID); updateCommand.Parameters.AddWithValue("@OldCatholic_Party_Category", oldCatholic_Party.Catholic_Party_Category); try { connection.Open(); int count = updateCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public static bool Delete(Bride clsBride) { SqlConnection connection = MarriageData.GetConnection(); string deleteStatement = "DELETE FROM " + " [Bride] " + "WHERE " + " [Bride_ID] = @OldBride_ID " + " AND [Bride_First_Name] = @OldBride_First_Name " + " AND [Bride_Middle_Int] = @OldBride_Middle_Int " + " AND [Bride_Last_Name] = @OldBride_Last_Name " + ""; SqlCommand deleteCommand = new SqlCommand(deleteStatement, connection); deleteCommand.CommandType = CommandType.Text; deleteCommand.Parameters.AddWithValue("@OldBride_ID", clsBride.Bride_ID); deleteCommand.Parameters.AddWithValue("@OldBride_First_Name", clsBride.Bride_First_Name); deleteCommand.Parameters.AddWithValue("@OldBride_Middle_Int", clsBride.Bride_Middle_Int); deleteCommand.Parameters.AddWithValue("@OldBride_Last_Name", clsBride.Bride_Last_Name); try { connection.Open(); int count = deleteCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public static bool Add(Catholic_Party clsCatholic_Party) { SqlConnection connection = MarriageData.GetConnection(); string insertStatement = "INSERT " + " [Catholic_Party] " + " ( " + " [Catholic_Party_Category] " + " ) " + "VALUES " + " ( " + " @Catholic_Party_Category " + " ) " + ""; SqlCommand insertCommand = new SqlCommand(insertStatement, connection); insertCommand.CommandType = CommandType.Text; insertCommand.Parameters.AddWithValue("@Catholic_Party_Category", clsCatholic_Party.Catholic_Party_Category); try { connection.Open(); int count = insertCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public static bool Delete(Log clsLog) { SqlConnection connection = MarriageData.GetConnection(); string deleteStatement = "DELETE FROM " + " [Log] " + "WHERE " + " [Log_ID] = @OldLog_ID " + " AND [User_Name] = @OldUser_Name " + " AND [Note] = @OldNote " + ""; SqlCommand deleteCommand = new SqlCommand(deleteStatement, connection); deleteCommand.CommandType = CommandType.Text; deleteCommand.Parameters.AddWithValue("@OldLog_ID", clsLog.Log_ID); deleteCommand.Parameters.AddWithValue("@OldUser_Name", clsLog.User_Name); deleteCommand.Parameters.AddWithValue("@OldNote", clsLog.Note); try { connection.Open(); int count = deleteCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public static bool Delete(Parish clsParish) { SqlConnection connection = MarriageData.GetConnection(); string deleteStatement = "DELETE FROM " + " [Parish] " + "WHERE " + " [Parish_ID] = @OldParish_ID " + " AND [ParishName] = @OldParishName " + " AND [KCSJDiocese] = @OldKCSJDiocese " + ""; SqlCommand deleteCommand = new SqlCommand(deleteStatement, connection); deleteCommand.CommandType = CommandType.Text; deleteCommand.Parameters.AddWithValue("@OldParish_ID", clsParish.Parish_ID); deleteCommand.Parameters.AddWithValue("@OldParishName", clsParish.ParishName); deleteCommand.Parameters.AddWithValue("@OldKCSJDiocese", clsParish.KCSJDiocese); try { connection.Open(); int count = deleteCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public static DataTable SelectAll() { SqlConnection connection = MarriageData.GetConnection(); string selectStatement = "SELECT " + " [Bride I D] = [Bride].[Bride_ID] " + " ,[Bride First Name] = [Bride].[Bride_First_Name] " + " ,[Bride Middle Int] = [Bride].[Bride_Middle_Int] " + " ,[Bride Last Name] = [Bride].[Bride_Last_Name] " + "FROM " + " [Bride] " + ""; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.CommandType = CommandType.Text; DataTable dt = new DataTable(); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(); if (reader.HasRows) { dt.Load(reader); } reader.Close(); } catch (SqlException) { return(dt); } finally { connection.Close(); } return(dt); }
public static bool Delete(Catholic_Party clsCatholic_Party) { SqlConnection connection = MarriageData.GetConnection(); string deleteStatement = "DELETE FROM " + " [Catholic_Party] " + "WHERE " + " [Catholic_Party_ID] = @OldCatholic_Party_ID " + " AND [Catholic_Party_Category] = @OldCatholic_Party_Category " + ""; SqlCommand deleteCommand = new SqlCommand(deleteStatement, connection); deleteCommand.CommandType = CommandType.Text; deleteCommand.Parameters.AddWithValue("@OldCatholic_Party_ID", clsCatholic_Party.Catholic_Party_ID); deleteCommand.Parameters.AddWithValue("@OldCatholic_Party_Category", clsCatholic_Party.Catholic_Party_Category); try { connection.Open(); int count = deleteCommand.ExecuteNonQuery(); if (count > 0) { return(true); } else { return(false); } } catch (SqlException ex) { throw ex; } finally { connection.Close(); } }
public static DataTable Search(string sField, string sCondition, string sValue) { SqlConnection connection = MarriageData.GetConnection(); string selectStatement = ""; if (sCondition == "Contains") { selectStatement = "SELECT " + " [Log].[Log_ID] " + " ,[Log].[User_Name] " + " ,[Log].[Note] " + "FROM " + " [Log] " + "WHERE " + " (@Log_ID IS NULL OR @Log_ID = '' OR [Log].[Log_ID] LIKE '%' + LTRIM(RTRIM(@Log_ID)) + '%') " + "AND (@User_Name IS NULL OR @User_Name = '' OR [Log].[User_Name] LIKE '%' + LTRIM(RTRIM(@User_Name)) + '%') " + "AND (@Note IS NULL OR @Note = '' OR [Log].[Note] LIKE '%' + LTRIM(RTRIM(@Note)) + '%') " + ""; } else if (sCondition == "Equals") { selectStatement = "SELECT " + " [Log].[Log_ID] " + " ,[Log].[User_Name] " + " ,[Log].[Note] " + "FROM " + " [Log] " + "WHERE " + " (@Log_ID IS NULL OR @Log_ID = '' OR [Log].[Log_ID] = LTRIM(RTRIM(@Log_ID))) " + "AND (@User_Name IS NULL OR @User_Name = '' OR [Log].[User_Name] = LTRIM(RTRIM(@User_Name))) " + "AND (@Note IS NULL OR @Note = '' OR [Log].[Note] = LTRIM(RTRIM(@Note))) " + ""; } else if (sCondition == "Starts with...") { selectStatement = "SELECT " + " [Log].[Log_ID] " + " ,[Log].[User_Name] " + " ,[Log].[Note] " + "FROM " + " [Log] " + "WHERE " + " (@Log_ID IS NULL OR @Log_ID = '' OR [Log].[Log_ID] LIKE LTRIM(RTRIM(@Log_ID)) + '%') " + "AND (@User_Name IS NULL OR @User_Name = '' OR [Log].[User_Name] LIKE LTRIM(RTRIM(@User_Name)) + '%') " + "AND (@Note IS NULL OR @Note = '' OR [Log].[Note] LIKE LTRIM(RTRIM(@Note)) + '%') " + ""; } else if (sCondition == "More than...") { selectStatement = "SELECT " + " [Log].[Log_ID] " + " ,[Log].[User_Name] " + " ,[Log].[Note] " + "FROM " + " [Log] " + "WHERE " + " (@Log_ID IS NULL OR @Log_ID = '' OR [Log].[Log_ID] > LTRIM(RTRIM(@Log_ID))) " + "AND (@User_Name IS NULL OR @User_Name = '' OR [Log].[User_Name] > LTRIM(RTRIM(@User_Name))) " + "AND (@Note IS NULL OR @Note = '' OR [Log].[Note] > LTRIM(RTRIM(@Note))) " + ""; } else if (sCondition == "Less than...") { selectStatement = "SELECT " + " [Log].[Log_ID] " + " ,[Log].[User_Name] " + " ,[Log].[Note] " + "FROM " + " [Log] " + "WHERE " + " (@Log_ID IS NULL OR @Log_ID = '' OR [Log].[Log_ID] < LTRIM(RTRIM(@Log_ID))) " + "AND (@User_Name IS NULL OR @User_Name = '' OR [Log].[User_Name] < LTRIM(RTRIM(@User_Name))) " + "AND (@Note IS NULL OR @Note = '' OR [Log].[Note] < LTRIM(RTRIM(@Note))) " + ""; } else if (sCondition == "Equal or more than...") { selectStatement = "SELECT " + " [Log].[Log_ID] " + " ,[Log].[User_Name] " + " ,[Log].[Note] " + "FROM " + " [Log] " + "WHERE " + " (@Log_ID IS NULL OR @Log_ID = '' OR [Log].[Log_ID] >= LTRIM(RTRIM(@Log_ID))) " + "AND (@User_Name IS NULL OR @User_Name = '' OR [Log].[User_Name] >= LTRIM(RTRIM(@User_Name))) " + "AND (@Note IS NULL OR @Note = '' OR [Log].[Note] >= LTRIM(RTRIM(@Note))) " + ""; } else if (sCondition == "Equal or less than...") { selectStatement = "SELECT " + " [Log].[Log_ID] " + " ,[Log].[User_Name] " + " ,[Log].[Note] " + "FROM " + " [Log] " + "WHERE " + " (@Log_ID IS NULL OR @Log_ID = '' OR [Log].[Log_ID] <= LTRIM(RTRIM(@Log_ID))) " + "AND (@User_Name IS NULL OR @User_Name = '' OR [Log].[User_Name] <= LTRIM(RTRIM(@User_Name))) " + "AND (@Note IS NULL OR @Note = '' OR [Log].[Note] <= LTRIM(RTRIM(@Note))) " + ""; } SqlCommand selectCommand = new SqlCommand(selectStatement, connection); selectCommand.CommandType = CommandType.Text; if (sField == "Log I D") { selectCommand.Parameters.AddWithValue("@Log_ID", sValue); } else { selectCommand.Parameters.AddWithValue("@Log_ID", DBNull.Value); } if (sField == "User Name") { selectCommand.Parameters.AddWithValue("@User_Name", sValue); } else { selectCommand.Parameters.AddWithValue("@User_Name", DBNull.Value); } if (sField == "Note") { selectCommand.Parameters.AddWithValue("@Note", sValue); } else { selectCommand.Parameters.AddWithValue("@Note", DBNull.Value); } DataTable dt = new DataTable(); try { connection.Open(); SqlDataReader reader = selectCommand.ExecuteReader(); if (reader.HasRows) { dt.Load(reader); } reader.Close(); } catch (SqlException) { return(dt); } finally { connection.Close(); } return(dt); }