Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. help me about insert

help me about insert

Scheduled Pinned Locked Moved C#
helpcsharpsecurityquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    albCode
    wrote on last edited by
    #1

    I create one appl. in C# and now i wanna insert string-text from textboxes to datagrid but it shows me one error. here is the code which i did write: The code is for InsertButton.I am not using storedProcedure. string ins = "INSERT INTO tabela(Column1,Column2,Column3,Columns4)VALUES ("+ "'"+ this.txtColumn1.Text + "'" + ","+ "'" + this.txtColumn2.Text + "'" + "," + "'" + this.txtColumn3.Text + "'" + "," + "'" + this.txtColumns4.Text + ")"; SqlConnection stringuu = new SqlConnection( "workstation id=mypc;packet size=4096;integrated security=SSPI;data source=mydatabase;persist security info=False;initial catalog="); SqlDataAdapter daa = new SqlDataAdapter(); DataSet dss = new DataSet(); daa.Fill(dss,"table"); SqlCommand inscomm= new SqlCommand(shtoje,stringuu); stringuu.Open(); inscomm.ExecuteNonQuery(); stringuu.Close(); can somebody tell me where is mistake???

    C C 2 Replies Last reply
    0
    • A albCode

      I create one appl. in C# and now i wanna insert string-text from textboxes to datagrid but it shows me one error. here is the code which i did write: The code is for InsertButton.I am not using storedProcedure. string ins = "INSERT INTO tabela(Column1,Column2,Column3,Columns4)VALUES ("+ "'"+ this.txtColumn1.Text + "'" + ","+ "'" + this.txtColumn2.Text + "'" + "," + "'" + this.txtColumn3.Text + "'" + "," + "'" + this.txtColumns4.Text + ")"; SqlConnection stringuu = new SqlConnection( "workstation id=mypc;packet size=4096;integrated security=SSPI;data source=mydatabase;persist security info=False;initial catalog="); SqlDataAdapter daa = new SqlDataAdapter(); DataSet dss = new DataSet(); daa.Fill(dss,"table"); SqlCommand inscomm= new SqlCommand(shtoje,stringuu); stringuu.Open(); inscomm.ExecuteNonQuery(); stringuu.Close(); can somebody tell me where is mistake???

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      seferi wrote: can somebody tell me where is mistake??? 1. "'" is superfluous, you could just put them in with the other text. 2. None of your variable names are remotely meaningful, in your code or ( far worse ) in your database 3. You didn't tell us what the error message was 4. Why aren't you using stored procedures, if you can ? Christian Graus - Microsoft MVP - C++

      1 Reply Last reply
      0
      • A albCode

        I create one appl. in C# and now i wanna insert string-text from textboxes to datagrid but it shows me one error. here is the code which i did write: The code is for InsertButton.I am not using storedProcedure. string ins = "INSERT INTO tabela(Column1,Column2,Column3,Columns4)VALUES ("+ "'"+ this.txtColumn1.Text + "'" + ","+ "'" + this.txtColumn2.Text + "'" + "," + "'" + this.txtColumn3.Text + "'" + "," + "'" + this.txtColumns4.Text + ")"; SqlConnection stringuu = new SqlConnection( "workstation id=mypc;packet size=4096;integrated security=SSPI;data source=mydatabase;persist security info=False;initial catalog="); SqlDataAdapter daa = new SqlDataAdapter(); DataSet dss = new DataSet(); daa.Fill(dss,"table"); SqlCommand inscomm= new SqlCommand(shtoje,stringuu); stringuu.Open(); inscomm.ExecuteNonQuery(); stringuu.Close(); can somebody tell me where is mistake???

        C Offline
        C Offline
        cjengler
        wrote on last edited by
        #3

        seferi wrote: string ins = "INSERT INTO tabela(Column1,Column2,Column3,Columns4)VALUES ("+ "'"+ this.txtColumn1.Text + "'" + ","+ "'" + this.txtColumn2.Text + "'" + "," + "'" + this.txtColumn3.Text + "'" + "," + "'" + this.txtColumns4.Text + ")"; Your first problem comes after your this.txtColumns4.Text. You forgot the ending "'". Like I said, that is your first problem and actually your smallest. Your biggest problem is that you are open for Sql Injection errors. You should really be using paramterized queries to prevent this. Please see http://www.codeproject.com/useritems/SqlWrapper.asp[this]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups