Click to See Complete Forum and Search --> : Delete from database


beeper
February 11th, 2005, 02:09 AM
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)
{

}

Krzemo
February 11th, 2005, 02:55 AM
The best (and the most universal) way is to use SQL "DELETE" command.

beeper
February 11th, 2005, 03:09 AM
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.