public static List<CPUData>GetCPU() { List<CPUData> cpu_list = new List<CPUData>(); SqlConnection conn = getConnection(); // string select_statement = "SELECT * FROM CPU ORDER BY CPU_rating"; string select_statement = "SELECT * FROM CPU"; SqlCommand select_command = new SqlCommand(select_statement,conn); try { conn.Open(); SqlDataReader reader = select_command.ExecuteReader(); while(reader.Read()) { CPUData CPU = new CPUData(); CPU.CPU_NAME = reader["CPU_NAME"].ToString(); CPU.CPU_RATING = reader["CPU_RATING"].ToString(); // CPU.CPU_VALUE = reader["CPU_VALUE"].ToString(); // CPU.CPU_LOWEST_PRICE_FOUND_ON_EBAY = reader["CPU_LOWEST_PRICE_FOUND_ON_EBAY"].ToString(); cpu_list.Add(CPU); } reader.Close(); } catch (SqlException ex) { throw ex; } finally { conn.Close(); } return cpu_list; }
public static List <CPUData> GetCPU() { List <CPUData> cpu_list = new List <CPUData>(); SqlConnection conn = getConnection(); // string select_statement = "SELECT * FROM CPU ORDER BY CPU_rating"; string select_statement = "SELECT * FROM CPU"; SqlCommand select_command = new SqlCommand(select_statement, conn); try { conn.Open(); SqlDataReader reader = select_command.ExecuteReader(); while (reader.Read()) { CPUData CPU = new CPUData(); CPU.CPU_NAME = reader["CPU_NAME"].ToString(); CPU.CPU_RATING = reader["CPU_RATING"].ToString(); // CPU.CPU_VALUE = reader["CPU_VALUE"].ToString(); // CPU.CPU_LOWEST_PRICE_FOUND_ON_EBAY = reader["CPU_LOWEST_PRICE_FOUND_ON_EBAY"].ToString(); cpu_list.Add(CPU); } reader.Close(); } catch (SqlException ex) { throw ex; } finally { conn.Close(); } return(cpu_list); }
public static void addCPU(CPUData cpu)//string CPU_name,int CPU_rating,float CPU_lowest_price_found_on_ebay,float CPU_value) { string CPU_name = cpu.CPU_NAME; string CPU_rating = cpu.CPU_RATING; // string CPU_lowest_price_found_on_ebay = cpu.CPU_LOWEST_PRICE_FOUND_ON_EBAY; // string CPU_value = cpu.CPU_VALUE; // string insert_statement = "INSERT INTO CPU(CPU_name, CPU_rating,CPU_lowest_price_found_on_ebay,CPU_value) VALUES (@CPU_name, @CPU_rating,@CPU_lowest_price_found_on_ebay,@CPU_value)"; string insert_statement = "INSERT INTO CPU(CPU_name, CPU_rating) VALUES (@CPU_name, @CPU_rating)"; SqlConnection conn = getConnection(); SqlCommand insert_command = new SqlCommand(insert_statement, conn); insert_command.Parameters.AddWithValue("@CPU_name", CPU_name); insert_command.Parameters.AddWithValue("@CPU_rating", CPU_rating); // insert_command.Parameters.AddWithValue("@CPU_lowest_price_found_on_ebay", CPU_lowest_price_found_on_ebay); // insert_command.Parameters.AddWithValue("@CPU_value", CPU_value); try { conn.Open(); insert_command.ExecuteNonQuery(); } catch (SqlException ex) { throw ex; } finally { conn.Close(); } }