Connecting Tech Pros Worldwide Help | Site Map

SQL connetion in C# page

Member
 
Join Date: Sep 2008
Posts: 72
#1: Oct 27 '08
hey guys hope you can help me with this error

with this button i whanne add values from an ASP webpage into my SQL database and i get an error on line 7 ( Embedded statement cannot be a declaration or labeled statement ) and the red line is only on the first Sql connection but not onder Conn

Expand|Select|Wrap|Line Numbers
  1.     private void Opslaan()
  2.         {
  3.         string Klant = ddlKlant.SelectedItem.Text;
  4.         string Leverancier = ddlLeverancier.SelectedItem.Text;
  5.         txtRef.Text = GenReferentieNr(txtRef.Text);
  6.             if (imgBtnVerzamelSave.Visible == true)
  7.             SqlConnection Conn = new SqlConnection();
  8.             Conn.ConnectionString = @"Integrated Security = true; Initial Catalog=DB_visitid; Data Source=W2K3-01";
  9.             Conn.Open();
  10.  
  11.             SqlCommand cmd = new SqlCommand();
  12.             cmd.Connection = Conn;
  13.             cmd.CommandText = "insert into offerte values ('"+Ref+"', '"+Leverancier+"', '"+TAV+"', '"+LevFax+"', '"+Klant+"', '"+Contact+"', '"+KlantFax+"', '"+Debetnr+"', '"+Omschrijving+"', '"+Aantal1+"', '"+Artikel1+"', '"+Bestelnr1+"', '"+OnzePrijs1+"', '"+PrijsKlant1+"', '"+LevTijd1+"', '"+Aantal2+"', '"+Artikel2+"', '"+Bestelnr2+"', '"+OnzePrijs2+"', '"+PrijsKlant2+"', '"+LevTijd2+"', '"+Aantal3+"', '"+Artikel3+"', '"+Bestelnr3+"', '"+OnzePrijs3+"', '"+PrijsKlant3+"', '"+LevTijd3+"', '"+Aantal4+"', '"+Artikel4+"', '"+Bestelnr4+"', '"+OnzePrijs4+"', '"+PrijsKlant4+"', '"+LevTijd4+"', '"+Aantal5+"', '"+Artikel5+"', '"+Bestelnr5+"', '"+OnzePrijs5+"', '"+PrijsKlant5+"', '"+LevTijd5+"', '"+Aantal6+"', '"+Artikel6+"', '"+Bestelnr6+"', '"+OnzePrijs6+"', '"+PrijsKlant6+"', '"+LevTijd6+"', '"+Aantal7+"', '"+Artikel7+"', '"+Bestelnr7+"', '"+OnzePrijs7+"', '"+PrijsKlant7+"', '"+LevTijd7+"', '"+Aantal8+"', '"+Artikel8+"', '"+Bestelnr8+"', '"+OnzePrijs8+"', '"+PrijsKlant8+"', '"+LevTijd8+"', '"+Aantal9+"', '"+Artikel9+"', '"+Bestelnr9+"', '"+OnzePrijs9+"', '"+PrijsKlant9+"', '"+LevTijd9+"', '"+Aantal10+"', '"+Artikel10+"', '"+Bestelnr10+"', '"+OnzePrijs10+"', '"+PrijsKlant10+"', '"+LevTijd10+"')";
  14.             Conn.Close();
  15.         }
I dont now if you need this code with it nut i maybe a easeyer to understand

Expand|Select|Wrap|Line Numbers
  1. private void imgBtnUpdate_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  2.         {
  3.             Opslaan();
  4.             Server.Transfer("VerzamelStatus.aspx?ID=" + txtRef.Text);
  5.         }
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Oct 27 '08

re: SQL connetion in C# page


This is the C and C++ forum. These languages have nothing to do with C#. I'll move
your thread to the .NET forum where the C# questions are asked and answered.

kind regards,

Jos (moderator)
Member
 
Join Date: Sep 2008
Posts: 72
#3: Oct 27 '08

re: SQL connetion in C# page


Well i ges i solved the error a bit logicly if i look at it now i still get another error but i first will look at it my self if i cant solve it youl here it here again Tnx for the help for the peaple whoe whanne see what i changed here is the code

Expand|Select|Wrap|Line Numbers
  1.     private void Opslaan()
  2.         {
  3.         string Klant = ddlKlant.SelectedItem.Text;
  4.         string Leverancier = ddlLeverancier.SelectedItem.Text;
  5.         txtRef.Text = GenReferentieNr(txtRef.Text);
  6.         if (imgBtnVerzamelSave.Visible == true)
  7.         {
  8.             SqlConnection Conn = new SqlConnection();
  9.             Conn.ConnectionString = @"Integrated Security = true; Initial Catalog=DB_visitid; Data Source=W2K3-01";
  10.             Conn.Open();
  11.             SqlCommand cmd = new SqlCommand();
  12.             cmd.Connection = Conn;
  13.             cmd.CommandText = "insert into offerte values ('" + txtRef + "', '" + Leverancier + "', '" + txtTAV + "', '" + txtLevFax + "', '" + Klant + "', '" + txtContact + "', '" + txtKlantFax + "', '" + txtDebetNr + "', '" + txtOmschrijving + "', '" + txtAantal1 + "', '" + txtArtikel1 + "', '" + txtBestelNr1 + "', '" + txtOnzePrijs1 + "', '" + txtPrijsKlant1 + "', '" + txtLevTijd1 + "', '" + txtAantal2 + "', '" + txtArtikel2 + "', '" + txtBestelNr2 + "', '" + txtOnzePrijs2 + "', '" + txtPrijsKlant2 + "', '" + txtLevTijd2 + "', '" + txtAantal3 + "', '" + txtArtikel3 + "', '" + txtBestelNr3 + "', '" + txtOnzePrijs3 + "', '" + txtPrijsKlant3 + "', '" + txtLevTijd3 + "', '" + txtAantal4 + "', '" + txtArtikel4 + "', '" + txtBestelNr4 + "', '" + txtOnzePrijs4 + "', '" + txtPrijsKlant4 + "', '" + txtLevTijd4 + "', '" + txtAantal5 + "', '" + txtArtikel5 + "', '" + txtBestelNr5 + "', '" + txtOnzePrijs5 + "', '" + txtPrijsKlant5 + "', '" + txtLevTijd5 + "', '" + txtAantal6 + "', '" + txtArtikel6 + "', '" + txtBestelNr6 + "', '" + txtOnzePrijs6 + "', '" + txtPrijsKlant6 + "', '" + txtLevTijd6 + "', '" + txtAantal7 + "', '" + txtArtikel7 + "', '" + txtBestelNr7 + "', '" + txtOnzePrijs7 + "', '" + txtPrijsKlant7 + "', '" + txtLevTijd7 + "', '" + txtAantal8 + "', '" + txtArtikel8 + "', '" + txtBestelNr8 + "', '" + txtOnzePrijs8 + "', '" + txtPrijsKlant8 + "', '" + txtLevTijd8 + "', '" + txtAantal9 + "', '" + txtArtikel9 + "', '" + txtBestelNr9 + "', '" + txtOnzePrijs9 + "', '" + txtPrijsKlant9 + "', '" + txtLevTijd9 + "', '" + txtAantal10 + "', '" + txtArtikel10 + "', '" + txtBestelNr10 + "', '" + txtOnzePrijs10 + "', '" + txtPrijsKlant10 + "', '" + txtLevTijd10 + "')";
  14.             Conn.Close();
  15.         }
  16.         }
Reply