I have a problem with inserting data into a sql server 2012.
My problem is that when I save Quantitaand Prezzothe values are changed! what can it be?. Quantita and Prezzo as Money values are taken from a datagridview I leave you under an example with the image of the datagridview used for insertion and the result of insertion into the database.
VALUE WITHIN DATAGRIDVIEW:
AFTER INSERT INTO SQL-SERVER:
SqlConnection conn = db.apriconnessione();
SqlTransaction sqlTran = conn.BeginTransaction();
try
{
//avvio la transazione
SqlCommand command = conn.CreateCommand();
command.Transaction = sqlTran;
//InserimentoBolla
DateTime dataconvertita = Convert.ToDateTime(labelDATADDTMOD.Text);
command.CommandText = "SET IDENTITY_INSERT Bolla ON";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO Bolla(NumeroDDT,IdCantiere,DataDDT,Agente,RagioneSociale,CodiceCliente,RiferimentiInterni,Importo,Destinazione,Filiale,Magazzino,Preparato,Vettore,TipoTrasporto) VALUES('" + labelNUMDDTMOD.Text+"','"+IdCantiere+"',convert(datetime,'"+dataconvertita+"', 103),'" + labelAgenteMOD.Text+"','"+labelRagioneSocialeMOD.Text+"','"+int.Parse(labelCodiceClienteMOD.Text)+"','"+labelRIFInternoMOD.Text+"','"+float.Parse(labelImportoMOD.Text)+"','"+labelDestMOd.Text+"','"+labelFilialeMOD.Text+"','"+labelMagazzinoMOD.Text+"','"+labelPreparatodaMOD.Text+"','"+labelvettoreMOD.Text+"','"+labelTipoTrasportoMOD.Text+"')";
command.ExecuteNonQuery();
command.CommandText = "SET IDENTITY_INSERT Bolla OFF";
command.ExecuteNonQuery();
//fine bolla
//inserimento articolo
for (int rows = 0; rows < dataGridViewArticoli.Rows.Count; rows++)
{
string Fornitore = dataGridViewArticoli.Rows[rows].Cells[0].Value.ToString();
string ModelloFornitore = dataGridViewArticoli.Rows[rows].Cells[1].Value.ToString();
string SiglaMetel = dataGridViewArticoli.Rows[rows].Cells[2].Value.ToString();
string CodiceMetel = dataGridViewArticoli.Rows[rows].Cells[3].Value.ToString();
string CodiceInterno = dataGridViewArticoli.Rows[rows].Cells[4].Value.ToString();
string Descrizione = dataGridViewArticoli.Rows[rows].Cells[5].Value.ToString();
float prezzo = float.Parse(dataGridViewArticoli.Rows[rows].Cells[6].Value.ToString());
// MessageBox.Show(" "+prezzo);
float quantita = float.Parse(dataGridViewArticoli.Rows[rows].Cells[8].Value.ToString());
// MessageBox.Show("Quantita: "+quantita);
command.CommandText = "INSERT INTO ArticoloCantiere(IdCantiere,IdUtente,CodArt,CodMarca,CodiceInterno,ModelloFornitore,Prezzo,Quantita,Fornitore,Importato) VALUES('" + IdCantiere + "','"+u.IdUtente+"','" + CodiceMetel + "','" + SiglaMetel + "','" + CodiceInterno + "','" + ModelloFornitore + "','" + prezzo + "','" + quantita + "','COMET','BOLLA')";
command.ExecuteNonQuery();
}
//fine inserimento articolo
//conferma delle transazioni con la commit
sqlTran.Commit();
}
catch (Exception ex)
{
sqlTran.Rollback();
MessageBox.Show("Errore nell'inserimento "+ex);
}
conn.Close();
this.DialogResult = DialogResult.OK;
this.Close();

