Ho un datagrid che contiene un elenco di textbox nei quali devo inserire una ripartizione che da 100

ho un problema... la pagina a volte mi va in errore

"The connection is already Open (state=Open)"

mi sembra di aver capito che:

se inserisco pochi valori (es: 40,40,20) è tutto ok;


ma se inserisco piu valori (20,20,20,20,10,10) ottengo l'errore: The connection is already Open (state=Open).


il codice è questo..... dove sbaglio??????

if (TotPerc.Text == "100")

{



// cancello tutti i dati presenti nella tabella ripartizione ldb per la riga selezionata

OleDbCommand myCommandDel = new OleDbCommand("SP_FatturaLibera_Ldb_Delete",myConne ctionDelete);

myCommandDel.CommandType=CommandType.StoredProcedu re;

myCommandDel.Parameters.Add("@IDRiga", OleDbType.VarChar);

myCommandDel.Parameters["@IDRiga"].Value = IDRiga;




try

{

myConnectionDelete.Open();

myCommandDel.ExecuteNonQuery();

myConnectionDelete.Close();

}

catch (Exception exc)

{

DebugErrore.Text = exc.Message;

myConnectionDelete.Close();

}





foreach(DataGridItem item in MyDataGrid.Items)

{

string ldb = ((Label)item.FindControl("IDVoce")).Text;

string importo = ((TextBox)item.FindControl("TotaleText")).Text;


try

{


OleDbCommand myCommand = new OleDbCommand("SP_FatturaLibera_LdbInsert", myConnectionIns);

myCommand.CommandType=CommandType.StoredProcedure;



myCommand.Parameters.Add(new OleDbParameter("@NumeroFattura", OleDbType.VarChar));

myCommand.Parameters.Add(new OleDbParameter("@IDRiga", OleDbType.VarChar));

myCommand.Parameters.Add(new OleDbParameter("@LDB", OleDbType.VarChar));

myCommand.Parameters.Add(new OleDbParameter("@Valore", OleDbType.VarChar));




if (NumeroFattura.ToString() != "")

{

myCommand.Parameters["@NumeroFattura"].Value = NumeroFattura.ToString();

}

else

{

myCommand.Parameters["@NumeroFattura"].Value = DBNull.Value;

}





myCommand.Parameters["@IDRiga"].Value = IDRiga.ToString();




if (ldb.ToString() != "")

{

myCommand.Parameters["@LDB"].Value = ldb;

}

else

{

myCommand.Parameters["@LDB"].Value = DBNull.Value;

}





if (importo.ToString() != "")

{

myCommand.Parameters["@Valore"].Value = importo;

}

else

{

myCommand.Parameters["@Valore"].Value = "0";

}



myConnectionIns.Open();

myCommand.ExecuteNonQuery();

myConnectionIns.Close();




}

// intercettto l'errore di un'eventuale concorrenza nella scrittura

catch (Exception exc)

{

DebugErrore.Text = exc.Message;


}


}





// chiudo la finestra per le ripartizioni LDB

string scriptString;

scriptString = "<script language=JavaScript>";

scriptString = scriptString + "window.close();";

scriptString = scriptString + "</script>";

Page.RegisterClientScriptBlock("clientScript", scriptString);





}

// fine if

else

{

DebugErrore.Text = "Il totale della ripartizione delle LDB deve dare 100%";

}