Hi!!!
I have made a database application and I am unable to delete the record in it.There is one comboobx, a textbox and a listview.For each item selected in combobox I am adding corresponding item entered in textbox . And each combobox and textbox item are displaying in listview.In database we have 3 fields one for combox field , second for id of textbox(primary key) and third is textbox item. The code is as follows:
private void btn_Delete_Click(object sender, EventArgs e)
{
if (this.com_sName.DropDownStyle == ComboBoxStyle.Simple)
{
this.com_sName.DropDownStyle = ComboBoxStyle.DropDownList;
}
section_Delete();
lstv_Function();
}
private void section_Delete()
{
DialogResult ret;
ret = MessageBox.Show("Are you sure to delete record!", "Delete".ToUpper(), MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
if (ret == DialogResult.Yes)
{
if (this.txt_Sname.Text == "")
{
MessageBox.Show("Some required Fields are Empty!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
try
{
this.clsCon.cmdOpen(cmdForm);
cmdForm.CommandText = "delete * from [section] where sec_id=?";
cmdForm.Parameters.Add("@sec_id", OleDbType.Numeric).Value = this.editID;
clsCon.cmdClose(cmdForm);
clsmyFunction.setMessageBox("Data Deleted Successfuly", 1);
}
catch (Exception exp)
{
clsmyFunction.setCreateError(exp.Message);
}
finally
{
this.clsCon.cn.Close();
}
}
}
else
{
return;
}
}
private void comboClass_Load()
{
this.clsCon.comboFill(this.com_sName, "select * from class", "class", "c_name", "c_id");
}
private void lstv_Class_SelectedIndexChanged(object sender, EventArgs e)
{
this.editID = (this.lstv_Section.Items[lstv_Section.FocusedItem.Index].SubItems[0].Text.Trim());
this.txt_Sname.Text = (this.lstv_Section.Items[lstv_Section.FocusedItem.Index].SubItems[1].Text.Trim());
}
Kindly provide some solution......