我有一个问题,插入数据到sql server 2012
。
我的问题是,当我保存Quantita
和Prezzo
值改变了!它可能是什么? Quantita
和Prezzo
as Money
values are from a datagridview我给你留下一个例子,用datagridview
用于插入图像和插入数据库的结果。错误查询Sql Server插入,不正确的值格式C#
值范围内的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();
请问我有什么难以理解你说什么,请你纠正一点你的语法? – Esperadoce
好的一刻.... – riki
尝试:float prezzo = dataGridViewArticoli.Rows [rows] .Cells [6] .Value; – jdweng