CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005
    Posts
    34

    Cool Delete from database

    How i can delete records from database. I show a record in datagrid. Using Click Action on datagrid.
    I have only this, and no idea.
    Or where i can find a solution.
    Thanks

    this.dataGrid.Click += new System.EventHandler(this.dataGrid_Click);
    //---//
    private void dataGrid_Click(object sender, System.EventArgs e)
    {

    }
    Last edited by beeper; February 11th, 2005 at 03:12 AM.

  2. #2
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    Re: Delete from database

    The best (and the most universal) way is to use SQL "DELETE" command.

  3. #3
    Join Date
    Jan 2005
    Posts
    34

    Re: Delete from database

    I got this

    private void dataGrid_Click(object sender, System.EventArgs e)
    {
    try
    {
    int row=dataGridWInfOPracownikach.CurrentCell.RowNumber;
    int col= dataGrid.CurrentCell.ColumnNumber;
    object id=dataGrid[row,col];
    object emp=dataGrid[row,col+1];

    MySQLConnection cn;
    cn=new MySQLConnection(new MySQLConnectionString
    (
    *
    ).AsString );
    cn.Open();

    string message="Delete employe? '"+emp.ToString()+"' ?";
    string caption="Q";
    MessageBoxButtons buttons=MessageBoxButtons.YesNo;
    DialogResult result;
    result = MessageBox.Show(this,message,caption,buttons);

    if(result==DialogResult.Yes)
    {
    MySQLCommand delete=new MySQLCommand("DELETE FROM employe WHERE ID="+id+"",cn);

    delete.ExecuteNonQuery();
    fnRefreshBind();

    }


    I wan to change that. When i focus a row, i must click Button "Delete" and then delete from db.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured