SQL connetion in C# page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asmx126453
    New Member
    • Sep 2008
    • 72

    SQL connetion in C# page

    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

    Code:
    	private void Opslaan()
            {
    		string Klant = ddlKlant.SelectedItem.Text;
    		string Leverancier = ddlLeverancier.SelectedItem.Text;
    		txtRef.Text = GenReferentieNr(txtRef.Text);
                if (imgBtnVerzamelSave.Visible == true)
                SqlConnection Conn = new SqlConnection();
                Conn.ConnectionString = @"Integrated Security = true; Initial Catalog=DB_visitid; Data Source=W2K3-01";
                Conn.Open();
    
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = Conn;
                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+"')";
                Conn.Close();
            }
    I dont now if you need this code with it nut i maybe a easeyer to understand

    Code:
    private void imgBtnUpdate_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    		{
    			Opslaan();
    			Server.Transfer("VerzamelStatus.aspx?ID=" + txtRef.Text);
    		}
    Last edited by asmx126453; Oct 27 '08, 08:57 AM. Reason: Adding information
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    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)

    Comment

    • asmx126453
      New Member
      • Sep 2008
      • 72

      #3
      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

      Code:
      	private void Opslaan()
              {
      		string Klant = ddlKlant.SelectedItem.Text;
      		string Leverancier = ddlLeverancier.SelectedItem.Text;
      		txtRef.Text = GenReferentieNr(txtRef.Text);
              if (imgBtnVerzamelSave.Visible == true)
              {
                  SqlConnection Conn = new SqlConnection();
                  Conn.ConnectionString = @"Integrated Security = true; Initial Catalog=DB_visitid; Data Source=W2K3-01";
                  Conn.Open();
                  SqlCommand cmd = new SqlCommand();
                  cmd.Connection = Conn;
                  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 + "')";
                  Conn.Close();
              }
              }

      Comment

      Working...