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......

>delete * from [section] where sec..

delete from [section] ...

>delete * from [section] where sec..

delete from [section] ...

No your code is not working..........
I am not getting any error and I don't understand why it is not deleting the record

Thanks I was able to solve it myself :cool:

The changes are shown in bold :

private void lstv_Class_SelectedIndexChanged(object sender, EventArgs e)
{

this.editID = (this.lstv_Section.Items[lstv_Section.FocusedItem.Index].SubItems[[B]1[/B]].Text.Trim());

this.txt_Sname.Text = (this.lstv_Section.Items[lstv_Section.FocusedItem.Index].SubItems[[B]2[/B]].Text.Trim());

}

>No your code is not working..........

It wasn't a code.

>I am not getting any error

Remove all try..catch from your code and then run it.

>I don't understand why it is not deleting the record

And even I don't. Please post exception trace.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.