Dim pos As Integer ds.Tables("OrderDetails").DefaultView.Sort = "COD_MITEM,COD_LOC" Dim vals(1) As Object vals(0) = e.Item.Cells(1).Text vals(1) = "B" pos = ds.Tables("OrderDetails").DefaultView.Find(vals) If pos <> -1 Then ds.Tables("OrderDetails").Rows(pos).Delete() MessagBox.Show("已經刪除") End If 然后再绑定
我在删除按钮下这面这么写可以吗?,还是要怎么写?if( this.dataGrid1.CurrentRowIndex < 0 ) return;
if( DialogResult.Yes == MessageBox.Show( "您确实要删除?", "确定", MessageBoxButtons.YesNo, MessageBoxIcon.Information ) )
{
SqlConnection Conn = new SqlConnection(connString );
try
{Conn.Open();
SqlCommand regCmd = Conn.CreateCommand();
string str = this.dataGrid1[ this.dataGrid1.CurrentCell ].ToString();
if( str == "" ) return;
string strSql = "delete from t_Sy where SyDm ='" + str + "'";
regCmd.CommandText = strSql;
regCmd.ExecuteNonQuery();
}
catch( Exception ex )
{
MessageBox.Show( ex.Message );
}
finally
{
Conn.Close();
}
ds.Tables("OrderDetails").DefaultView.Sort = "COD_MITEM,COD_LOC"
Dim vals(1) As Object
vals(0) = e.Item.Cells(1).Text
vals(1) = "B"
pos = ds.Tables("OrderDetails").DefaultView.Find(vals)
If pos <> -1 Then
ds.Tables("OrderDetails").Rows(pos).Delete() MessagBox.Show("已經刪除")
End If
然后再绑定
http://blog.csdn.net/zhzuo/archive/2005/01/03/238273.aspx