本文介绍了将winfrom中的数据保存到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在表单上有一个按钮可以将数据保存在数据库中,可以将数据保存到数据库中的2或3表中的按钮上,可以使用我的sintax.
On a form a have a button ho save data in the database, is ok to save data on a pres the button in 2 or 3 table in my data base, is ok the sintax i have.
<pre>private void btnVinde_Click(object sender, EventArgs e)<br />
{<br />
if (lblShared.Text == "1") { MessageBox.Show("Acest produse a fost vandut deja.", "Eroare.."); return; }<br />
if (txtVandutCu.Text.Trim().Length == 0) { MessageBox.Show("Nu ați introdus prețul de vâmzare.", "Datele introduse sunt incomplete."); return; }<br />
if (txtNumeComplet.Text.Trim().Length == 0) { MessageBox.Show("Selectați numele clientul pentru a putea vinde produsul.", "Datele introduse sunt incomplete."); return; }<br />
if (lblOperatie.Text == "1")<br />
{<br />
if (txtBonFiscal.Text.Trim().Length == 0)<br />
{<br />
MessageBox.Show("Nu ați introdus numărului bonului fiscal.", "Datele introduse sunt incomplete."); return;<br />
}<br />
}<br />
<br />
if (lblOperatie.Text == "1")<br />
{<br />
Program.Connection.CommandText = "insert into IesiriProduse(NrContract,DescriereProdus,NrNir,PretIesire,DataIesire) values (@NrContract,@DescriereProdus,@NrNir,@PretIesire,@DataIesire)";<br />
<br />
Program.Connection.AddParameter("@NrContract", txtCodProdus.Text);<br />
Program.Connection.AddParameter("@DescriereProdus", lblDescriereProdus.Text + ", Vândut cu bon fiscal nr. " + txtBonFiscal.Text + ", Conform contract nr. " + txtCodProdus.Text);<br />
Program.Connection.AddParameter("@NrNir", lblNrNir.Text);<br />
Program.Connection.AddParameter("@PretIesire", txtVandutCu.Text);<br />
Program.Connection.AddParameter("@DataIesire", DateTime.Now.ToString("dd.MM.yyyy"));<br />
Program.Connection.ExecuteNonQuery();<br />
<br />
}<br />
<br />
Program.Connection.CommandText = "update ProduseAmanet set CodClient=@CodClient, Shared=@Shared where IDProdus=" + CID;<br />
Program.Connection.AddParameter("@CodClient", lblCodClient.Text);<br />
Program.Connection.AddParameter("@Shared", Convert.ToInt32(1));<br />
Program.Connection.ExecuteNonQuery();<br />
<br />
<br />
<br />
Program.Connection.CommandText = "insert into ProduseVandute(IDProdus,IDClient,VandutDe,LaDataDe,LaOra,VandutCu,UserID,DescriereProdus,ContractNumar,PretAchizitie,SerialProdus,BonFiscal,AchizitiaLui,AlteInformatii) values (@IDProdus,@IDClient,@VandutDe,@LaDataDe,@LaOra,@VandutCu,@UserID,@DescriereProdus,@ContractNumar,@PretAchizitie,@SerialProdus,@BonFiscal,@AchizitiaLui,@AlteInformatii)";<br />
Program.Connection.AddParameter("@IDProdus", lblCodProdus.Text);<br />
Program.Connection.AddParameter("@IDClient", lblCodClient.Text);<br />
Program.Connection.AddParameter("@VandutDe", txtVandutDe.Text);<br />
Program.Connection.AddParameter("@LaDataDe",txtDataVanzare.Text);<br />
Program.Connection.AddParameter("@LaOra", txtOra.Text);<br />
Program.Connection.AddParameter("@VandutCu", txtVandutCu.Text);<br />
Program.Connection.AddParameter("@UserID", UserID);<br />
Program.Connection.AddParameter("@DescriereProdus", lblDescriereProdus.Text);<br />
Program.Connection.AddParameter("@ContractNumar", txtCodProdus.Text);<br />
Program.Connection.AddParameter("@PretAchizitie", lblPretAchiztie.Text);<br />
Program.Connection.AddParameter("@SerialProdus", txtSerialProdus.Text);<br />
Program.Connection.AddParameter("@BonFiscal", txtBonFiscal.Text);<br />
Program.Connection.AddParameter("@AchizitiaLui", lblAchizitielui.Text);<br />
Program.Connection.AddParameter("@AlteInformatii", txtAlteInformatii.Text);<br />
<br />
<br />
Program.Connection.ExecuteNonQuery();<br />
<br />
<br />
this.Close();<br />
<br />
<br />
<br />
//Create the object person and assign the values<br />
CertificatGarantie DateGarantie = new CertificatGarantie();<br />
DateGarantie.Name = txtNumeComplet.Text;<br />
DateGarantie.ContractCod = txtCodProdus.Text;<br />
DateGarantie.Country = txtDataVanzare.Text;<br />
DateGarantie.Email = lblAdresaClient.Text;<br />
DateGarantie.isSerialProdus = txtSerialProdus.Text;<br />
<br />
<br />
<br />
DateGarantie.DescriereProdus = lblDescriereProdus.Text;<br />
DateGarantie.IsMale = txtGarantieZile.Text;<br />
DateGarantie.isRetail = txtRetur.Text;<br />
DateGarantie.isUM = txtCantitate.Text;<br />
<br />
//Create the object Report and assign object to report<br />
HTMLReport html = new HTMLReport();<br />
//Assign the template file <br />
html.Template = "SablonGarantie.htm";<br />
//Asign the new file name<br />
html.FileName = DateGarantie.Name;<br />
//Generate the new Page and open it. It uses default browser<br />
System.Diagnostics.Process.Start(html.Generate(DateGarantie));<br />
<br />
}</pre>
推荐答案
这篇关于将winfrom中的数据保存到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!