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. Database delete [modified]

Database delete [modified]

Scheduled Pinned Locked Moved C#
databasehelpsecurity
5 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.
  • D Offline
    D Offline
    drc_no1
    wrote on last edited by
    #1

    Hey! I ran into a little problem today... i think it's an easy one, but i don't have the answer. I have a string n declared and i want to delete all the rows in one database(sql) which contain that string(completely, not parts of the cells in the databases). so i wrote: SqlConnection sqlconn = new SqlConnection(); sqlconn.ConnectionString = "Data Source=CATA;Initial Catalog=datagrid;Integrated Security=True;Pooling=False"; sqlconn.Open(); SqlCommand sqlcomm = new SqlCommand(); sqlcomm.CommandText = "DELETE FROM datagrid WHERE name ='"&n&"'"; sqlcomm.Connection = sqlconn; sqlcomm.ExecuteNonQuery(); but i get the following message when i try to run the program: Error 1 Operator '&' cannot be applied to operands of type 'string' and 'string' -- modified at 7:35 Tuesday 23rd May, 2006

    R S 2 Replies Last reply
    0
    • D drc_no1

      Hey! I ran into a little problem today... i think it's an easy one, but i don't have the answer. I have a string n declared and i want to delete all the rows in one database(sql) which contain that string(completely, not parts of the cells in the databases). so i wrote: SqlConnection sqlconn = new SqlConnection(); sqlconn.ConnectionString = "Data Source=CATA;Initial Catalog=datagrid;Integrated Security=True;Pooling=False"; sqlconn.Open(); SqlCommand sqlcomm = new SqlCommand(); sqlcomm.CommandText = "DELETE FROM datagrid WHERE name ='"&n&"'"; sqlcomm.Connection = sqlconn; sqlcomm.ExecuteNonQuery(); but i get the following message when i try to run the program: Error 1 Operator '&' cannot be applied to operands of type 'string' and 'string' -- modified at 7:35 Tuesday 23rd May, 2006

      R Offline
      R Offline
      RC_Sebastien_C
      wrote on last edited by
      #2

      drc_no1 wrote:

      sqlcomm.CommandText = "DELETE FROM datagrid WHERE name ='"&n&"'";

      that would be: WHERE name ='" + n + "'";

      D 1 Reply Last reply
      0
      • D drc_no1

        Hey! I ran into a little problem today... i think it's an easy one, but i don't have the answer. I have a string n declared and i want to delete all the rows in one database(sql) which contain that string(completely, not parts of the cells in the databases). so i wrote: SqlConnection sqlconn = new SqlConnection(); sqlconn.ConnectionString = "Data Source=CATA;Initial Catalog=datagrid;Integrated Security=True;Pooling=False"; sqlconn.Open(); SqlCommand sqlcomm = new SqlCommand(); sqlcomm.CommandText = "DELETE FROM datagrid WHERE name ='"&n&"'"; sqlcomm.Connection = sqlconn; sqlcomm.ExecuteNonQuery(); but i get the following message when i try to run the program: Error 1 Operator '&' cannot be applied to operands of type 'string' and 'string' -- modified at 7:35 Tuesday 23rd May, 2006

        S Offline
        S Offline
        S Senthil Kumar
        wrote on last edited by
        #3

        While HollyHoo's suggestion would probably work, I suggest you read this[^] article to know why your code is vulnerable to SQL injection attacks. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

        R 1 Reply Last reply
        0
        • R RC_Sebastien_C

          drc_no1 wrote:

          sqlcomm.CommandText = "DELETE FROM datagrid WHERE name ='"&n&"'";

          that would be: WHERE name ='" + n + "'";

          D Offline
          D Offline
          drc_no1
          wrote on last edited by
          #4

          Yup, it works. Thanx a lot! Now i have another problem... I have a datagrid and i have added one button column called delete. when i press delete, i want my row to disappear. But, i can't find a suitable event for clicking that button. all i find is cell content click or any other that aplies to the whole row, not only to that cell contining the row. Can u help me, pls?

          1 Reply Last reply
          0
          • S S Senthil Kumar

            While HollyHoo's suggestion would probably work, I suggest you read this[^] article to know why your code is vulnerable to SQL injection attacks. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

            R Offline
            R Offline
            RC_Sebastien_C
            wrote on last edited by
            #5

            Very good suggestion

            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