redrose4u293
New member
- Joined
- Aug 24, 2021
- Messages
- 4
- Programming Experience
- Beginner
C#:
try
{
con = new SqlConnection(cs);
con.Open();
string p_comp="";
if (cmbH_ID.Text == "Select" || cmbH_ID.Text == "")
{
p_comp = "INSERT INTO Supply (SUPPLY_DATE,B_ID,D_I_ID,M_ID,ST_ID) VALUES (@SUPPLY_DATE,@B_ID,@D_I_ID,@M_ID, @ST_ID) ";
cmd = new SqlCommand(p_comp);
cmd.Connection = con;
cmd.Parameters.AddWithValue("@SUPPLY_DATE", dateTimePicker1.Value.Date);
cmd.Parameters.AddWithValue("@M_ID", textBox2.Text);
cmd.Parameters.AddWithValue("@B_ID", textBox3.Text);
cmd.Parameters.AddWithValue("@D_I_ID", cmbDis_ID.Text);
cmd.Parameters.AddWithValue("@ST_ID", cmbS_id.Text);
}
if (cmbS_id.Text == "Select" || cmbS_id.Text == "")
{
p_comp = "INSERT INTO Supply (SUPPLY_DATE,B_ID,D_I_ID,H_ID,M_ID) VALUES (@SUPPLY_DATE,@B_ID,@D_I_ID,@H_ID,@M_ID) ";
cmd = new SqlCommand(p_comp);
cmd.Connection = con;
cmd.Parameters.AddWithValue("@SUPPLY_DATE", dateTimePicker1.Value.Date);
cmd.Parameters.AddWithValue("@H_ID", cmbH_ID.Text);
cmd.Parameters.AddWithValue("@M_ID", textBox2.Text);
cmd.Parameters.AddWithValue("@B_ID", textBox3.Text);
cmd.Parameters.AddWithValue("@D_I_ID", cmbDis_ID.Text);
}
cmd = new SqlCommand(p_comp);
cmd.Connection = con;
cmd.Parameters.AddWithValue("@SUPPLY_DATE", dateTimePicker1.Value.Date);
cmd.Parameters.AddWithValue("@H_ID", cmbH_ID.Text);
cmd.Parameters.AddWithValue("@M_ID", textBox2.Text);
cmd.Parameters.AddWithValue("@B_ID", textBox3.Text);
cmd.Parameters.AddWithValue("@D_I_ID", cmbDis_ID.Text);
cmd.Parameters.AddWithValue("@ST_ID", cmbS_id.Text);
cmd.ExecuteReader();
MessageBox.Show("Successfully saved", "Supply Details", MessageBoxButtons.OK, MessageBoxIcon.Information);
btnSave.Enabled = false;
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Last edited by a moderator: