2012-03-16 66 views
1

在我的C#appliaction現在面臨的問題在下面的代碼,刪除從數據庫項目,sqlite的DataReader的

if (orderedRelationSet.RemoveRelation(relation) != true) 
{ 
    TouchServer.Log(Logger.MessageType.Error, 0,  OrderedRelationSet.error_msg + "Remove relation operation failed"); 
    throw new Exception("remove relation failed"); 
} 



public bool RemoveRelation(Relation relation) 
{ 
    Relation relationToRemove = null; 
    relationToRemove = relation; 

    int roweffected = 0; 
    int flg_delete = 0; 

    int ordinal_source = 0; 

    if (relationToRemove != null) 
    { 

     SQLiteDataReader dr_readtype = db.ExecuteSQL("select typeid from item where id=" + relation.ThingId + ""); 
     try 
     { 
      dr_readtype.Read(); 
      type_id = Convert.ToInt32(dr_readtype[0]); 
     } 
     catch (Exception) 
     { 
     } 
     finally 
     { 
      dr_readtype.Close(); 
      dr_readtype.Dispose(); 

     } 

     SQLiteDataReader dr_ordinal = db.ExecuteSQL("select ordinal from relation where parent_itemid=" + relation.SourceThingId + " and child_itemid= " + relation.ThingId + ""); 
     try 
     { 
      dr_ordinal.Read(); 
      ordinal_source = Convert.ToInt32(dr_ordinal[0]); 
     } 
     catch (Exception) 
     { 
     } 
     finally 
     { 
      dr_ordinal.Close(); 
      dr_ordinal.Dispose(); 
     } 


     if (flg_delete == 0 || db.currentUser.UserName=="System") 
     { 
      relations.Remove(relationToRemove); 
      roweffected = relationToRemove.UnSet(); 

      type_id = 0; 
     } 
    } 
    if (roweffected >= 1) 
    { 

     SQLiteDataReader dr_ordinal = db.ExecuteSQL("select ordinal,child_itemid from relation where parent_itemid=" + relation.SourceThingId + " and ordinal > " + ordinal_source + ""); 
     Hashtable list = new Hashtable(); 
     try 
     { 
      while (dr_ordinal.Read()) 
      { 
       list.Add(int.Parse(dr_ordinal[1].ToString()), int.Parse(dr_ordinal[0].ToString())); 
       //lis1.Add(int.Parse(dr_ordinal[1].ToString())); 
      } 
     } 
     catch (Exception) 
     { 
     } 
     finally 
     { 
      dr_ordinal.Close(); 
      dr_ordinal.Dispose() 
     } 
     int j = 0; 
     foreach (int key in list.Keys) 
     { 
      int ordi = (int)list[key]; 
      int ordinal_result = ordi - 1; 

      try 
      { 
       string sqlExpr = "update relation set [email protected]_result where [email protected]_SourceThingId and [email protected]"; 
       SQLiteCommand _updateRelation = new SQLiteCommand(); 
       _updateRelation.CommandText = sqlExpr; 
       _updateRelation.Parameters.AddWithValue("@ordinal_result", ordinal_result); 
       _updateRelation.Parameters.AddWithValue("@relation_SourceThingId", relation.SourceThingId); 
       _updateRelation.Parameters.AddWithValue("@key", key); 
       int update_sql = db.ExecuteNonQuerySQL(_updateRelation); 

      } 
      catch (Exception) 
      { 
      } 
      j++; 

     } 
     string sqlExprs = "UPDATE item SET modified [email protected],modifiedby [email protected] WHERE id [email protected]_SourceThingId"; 
     SQLiteCommand _updateItem = new SQLiteCommand(); 
     _updateItem.CommandText = sqlExprs; 
     _updateItem.Parameters.AddWithValue("@dates", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); 
     _updateItem.Parameters.AddWithValue("@currentUser", db.currentUser.id); 
     _updateItem.Parameters.AddWithValue("@relation_SourceThingId", relation.SourceThingId); 
     int affect = db.ExecuteNonQuerySQL(_updateItem); 

     return true; 
    } 
    else 
    {     
     return false; 
    } 

    flg_delete = 0; 
} 

它不是刪除數據.. 請幫助..

+0

您應該提供錯誤信息! – 2012-03-16 15:15:52

+0

它是刪除關係失敗。 – user703526 2012-03-16 15:19:28

+0

我正在刪除關係。 – user703526 2012-03-16 15:19:52

回答

2

你有很多

catch (Exception)   {   } 

但消息框與異常文本中有

catch (Exception E)   
    { 
     MessageBox.Show(E.ToString()); 
    }