private static int DoRegisterNewHdbbInDb(HdbbInfo hdbbDetails) { int returnVal = 0; MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection(); try { //define the command reference MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand(); //define the connection used by the command object msqlCommand.Connection = msqlConnection; msqlCommand.CommandText = "INSERT INTO hdbb(hdbb_id,hdbb_type,hdbb_name,hdbb_address,hdbb_contact) " + "VALUES(@hdbb_id,@hdbb_type,@hdbb_name,@hdbb_address,@hdbb_contact)"; msqlCommand.Parameters.AddWithValue("@hdbb_id", hdbbDetails.id); msqlCommand.Parameters.AddWithValue("@hdbb_type", hdbbDetails.type); msqlCommand.Parameters.AddWithValue("@hdbb_name", hdbbDetails.name); msqlCommand.Parameters.AddWithValue("@hdbb_address", hdbbDetails.address); msqlCommand.Parameters.AddWithValue("@hdbb_contact", hdbbDetails.phone); msqlCommand.ExecuteNonQuery(); returnVal = 1; } catch (Exception er) { returnVal = 0; } finally { //always close the connection msqlConnection.Close(); } return returnVal; }
public static int DoRegisterNewHdbb(HdbbInfo hdbbDetails) { return DoRegisterNewHdbbInDb(hdbbDetails); }
public static void EditHdbb(HdbbInfo hdbbToEdit) { MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection(); try { //define the command reference MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand(); msqlCommand.Connection = msqlConnection; msqlCommand.CommandText = "UPDATE hdbb SET hdbb_type=@hdbb_type,hdbb_name=@hdbb_name,hdbb_address=@hdbb_address,hdbb_contact=@hdbb_contact WHERE hdbb_id=@hdbb_id"; msqlCommand.Parameters.AddWithValue("@hdbb_type", hdbbToEdit.type); msqlCommand.Parameters.AddWithValue("@hdbb_name", hdbbToEdit.name); msqlCommand.Parameters.AddWithValue("@hdbb_address", hdbbToEdit.address); msqlCommand.Parameters.AddWithValue("@hdbb_contact", hdbbToEdit.phone); msqlCommand.Parameters.AddWithValue("@hdbb_id", hdbbToEdit.id); msqlCommand.ExecuteNonQuery(); } catch (Exception er) { } finally { //always close the connection msqlConnection.Close(); } }
private static List<HdbbInfo> QueryAllHdbbList() { List<HdbbInfo> HdbbList = new List<HdbbInfo>(); MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection(); try { //define the command reference MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand(); msqlCommand.Connection = msqlConnection; msqlCommand.CommandText = "Select * From hdbb;"; MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader(); while (msqlReader.Read()) { HdbbInfo Hdbb = new HdbbInfo(); Hdbb.id = msqlReader.GetString("hdbb_id"); Hdbb.type = msqlReader.GetString("hdbb_type"); Hdbb.name = msqlReader.GetString("hdbb_name"); Hdbb.address = msqlReader.GetString("hdbb_address"); Hdbb.phone = msqlReader.GetString("hdbb_contact"); HdbbList.Add(Hdbb); } } catch (Exception er) { } finally { //always close the connection msqlConnection.Close(); } return HdbbList; }