public static void AddCoGiay(CoGiay item) { try { string connectionString = String.Format("Server={0};Database={1};Integrated Security={2};", Properties.Resources.ServerName, Properties.Resources.DatabaseName, Properties.Resources.Integrated_Security ); using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("ADD_COGIAY", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@MACOGIAY", item.MaCoGiay)); cmd.Parameters.Add(new SqlParameter("@TENCOGIAY", item.TenCoGiay)); cmd.Parameters.Add(new SqlParameter("@DAXOA", item.DaXoaCG)); cmd.ExecuteNonQuery(); } } catch { throw; } }
private void CbxCoGiay_SelectedValueChanged(object sender, EventArgs e) { ComboBox combo = sender as ComboBox; if (combo.SelectedValue != null) { CoGiay cg = combo.SelectedValue as CoGiay; id_cg = cg.MaCoGiay.ToString(); ten_cg = cg.TenCoGiay.ToString(); } }
public static void AddCoGiay(CoGiay coGiay) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("https://localhost:44396/api/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); try { HttpResponseMessage response = client.PostAsJsonAsync("CoGiay", coGiay).Result; response.EnsureSuccessStatusCode(); } catch (Exception e) { throw e; } }