How to retrieve data from database to frontend, each field in diff txtbox #1 1 Minute Ago | Add to Haimanti's Reputation | Flag Bad Post
hi

Hi i'm new to coding, with basis of theritical knowledge, i tried writing code for data insert n retrieval..
the code i posted last time may be confusing, but its because i'm not comfortable with syntaxes still.

pls guidde with with the same.

Program requirement is:

The data in data grid should display "edit" and "delete" options when mouse is right clicked on it. The user when selects edit on any data, the whole related record should be displayed on new form where user may edit one or more field of the record n update the same in Db.

On selection of "delete' the user should have a msg box flashing if he is sure to delete the record. If "ok" the record may be deleted, if "cancel" the datagrid should be again dispalyed.

Pls guide me as to how do i proceed. I'm stuck on thi ssingle part since long

The code i've trid is as below:

private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //frmInsertCustData frmInsertCustData = new frmInsertCustData();
            //frmInsertCustData.Show();
            //DataSet ds = new DataSet();
            //SqlDataAdapter da = new SqlDataAdapter("Select * from customer order by id", conn1);
            //da.Fill(ds, "customer");
            //row = e.RowIndex;
            //col = e.ColumnIndex;

            

        }

        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //SqlDataReader dr1 = new SqlDataReader();
            //row = e.RowIndex;
            //col = e.ColumnIndex;


           //SqlDataAdapter da1 = new SqlDataAdapter("Delete from customer where @parameter =@value");
           // if (MessageBoxDefaultButton.Button1 = true)
           //     da1.ExecuteNonQuery();
           // else if (MessageBoxDefaultButton.Button2 = true)
           //     dataGridView2.Show();
  
            MessageBox.Show("Do you want to delete the record","Delete",MessageBoxButtons.OKCancel);
            DialogResult dialrslt = new DialogResult();
           frmInsertCustData myfrm = new frmInsertCustData();
            dialrslt = myfrm.ShowDialog();

            if (dialrslt == DialogResult.OK)
            {
             
                
                MessageBox.Show("Deleted Record!!");
            }

            else if (dialrslt == DialogResult.Cancel)
                MessageBox.Show("Action Reverted");

            
        }

Thank you

What compiler and operating system? I always used ODBC for database access and have no idea what SqlDataReader is.

[edit]Nevermind -- that thread was in the wrong forum [/edit]

Is this a web or windows app? coz if it a web message box isn't going to work you'll need js for the messages

Here is how you ask the user a question.. you have a lot of un-needed code.

private void simpleButton1_Click(object sender, EventArgs e)
    {
      if (MessageBox.Show("Delete record?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
        return;
      //Delete
    }

As far as deleting the data from the database you need to determine the currently selectly row's PRIMARY KEY. This depends on how you are presenting the data. Can you get it off the grids active row or from a bindingSource?

After you have the ID you will issue an SQL command to delete the record then remove it from the datasource's row collection.

Please post more information on how your form is setup.

This article has been dead for over six months. Start a new discussion instead.