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. sql query

sql query

Scheduled Pinned Locked Moved C#
databasehelpcsharpsql-serversysadmin
6 Posts 4 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.
  • M Offline
    M Offline
    Mahmood Ilyas
    wrote on last edited by
    #1

    i am using sql server along with C# i want to use both string and integer values in one query and i am writing this query below return "Insert INTO "+tableName+" (id,name,client,expstartdate,expenddate,cost,description)Values('+createpro.propertyPId+','"+createpro.propertyPname+"','"+createpro.propertyClient+"','"+createpro.propertyExpStDate+"','"+createpro.propertyExpEndDate+"','+createpro.propertycost+','"+createpro.propertydescription"')"; but this query giving an error, is this query is right for the solution of my problem; if not then give me the solution muhammad mahmood ilyas

    T C B 3 Replies Last reply
    0
    • M Mahmood Ilyas

      i am using sql server along with C# i want to use both string and integer values in one query and i am writing this query below return "Insert INTO "+tableName+" (id,name,client,expstartdate,expenddate,cost,description)Values('+createpro.propertyPId+','"+createpro.propertyPname+"','"+createpro.propertyClient+"','"+createpro.propertyExpStDate+"','"+createpro.propertyExpEndDate+"','+createpro.propertycost+','"+createpro.propertydescription"')"; but this query giving an error, is this query is right for the solution of my problem; if not then give me the solution muhammad mahmood ilyas

      T Offline
      T Offline
      testy_proconsul
      wrote on last edited by
      #2

      put your query string in a local variable and display it. you will see that there are missing quotes. it looks like you mixed quote and apostrophe up. try this (untested; im not sure about the date format): "Insert INTO " + tableName + " ( id, name, client, expstartdate, expenddate, cost, description) Values( " + createpro.propertyPId + ", " + "'" + createpro.propertyPname + "', " + createpro.propertyClient + ", " + "'" + createpro.propertyExpStDate + "', " + "'" + createpro.propertyExpEndDate+ "', " + "'" + createpro.propertycost + "', " + "'" + createpro.propertydescription + "'" + ")"

      1 Reply Last reply
      0
      • M Mahmood Ilyas

        i am using sql server along with C# i want to use both string and integer values in one query and i am writing this query below return "Insert INTO "+tableName+" (id,name,client,expstartdate,expenddate,cost,description)Values('+createpro.propertyPId+','"+createpro.propertyPname+"','"+createpro.propertyClient+"','"+createpro.propertyExpStDate+"','"+createpro.propertyExpEndDate+"','+createpro.propertycost+','"+createpro.propertydescription"')"; but this query giving an error, is this query is right for the solution of my problem; if not then give me the solution muhammad mahmood ilyas

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        Your code is highly susceptable to SQL Injection Attacks - resolving the security problems will also resolve your other problems. See SQL Injection Attacks and Tips on How To Prevent Them[^]


        Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

        1 Reply Last reply
        0
        • M Mahmood Ilyas

          i am using sql server along with C# i want to use both string and integer values in one query and i am writing this query below return "Insert INTO "+tableName+" (id,name,client,expstartdate,expenddate,cost,description)Values('+createpro.propertyPId+','"+createpro.propertyPname+"','"+createpro.propertyClient+"','"+createpro.propertyExpStDate+"','"+createpro.propertyExpEndDate+"','+createpro.propertycost+','"+createpro.propertydescription"')"; but this query giving an error, is this query is right for the solution of my problem; if not then give me the solution muhammad mahmood ilyas

          B Offline
          B Offline
          bannapradeep
          wrote on last edited by
          #4

          hi try this one:- "Insert INTO "+tableName+" (id,name,client,expstartdate,expenddate,cost,description)Values('+createpro.propertyPId+',' "+createpro.propertyPname+" ',' "+createpro.propertyClient+" ',' "+createpro.propertyExpStDate+" ',' "+createpro.propertyExpEndDate+" ','+createpro.propertycost+',' "+createpro.propertydescription" ')"; :-O

          C 1 Reply Last reply
          0
          • B bannapradeep

            hi try this one:- "Insert INTO "+tableName+" (id,name,client,expstartdate,expenddate,cost,description)Values('+createpro.propertyPId+',' "+createpro.propertyPname+" ',' "+createpro.propertyClient+" ',' "+createpro.propertyExpStDate+" ',' "+createpro.propertyExpEndDate+" ','+createpro.propertycost+',' "+createpro.propertydescription" ')"; :-O

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            What is it with people today - Just about every SQL question has been answered with something that simply invites an attacker into the system. In some cases warmly shaking the hand of the attacker as well while saying "Just take everythng you want" Securing a database against SQL Injection attacks is so unbelievably easy, yet no one today seems to care: SQL Injection Attacks and Tips on How to Prevent Them[^]


            Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

            M 1 Reply Last reply
            0
            • C Colin Angus Mackay

              What is it with people today - Just about every SQL question has been answered with something that simply invites an attacker into the system. In some cases warmly shaking the hand of the attacker as well while saying "Just take everythng you want" Securing a database against SQL Injection attacks is so unbelievably easy, yet no one today seems to care: SQL Injection Attacks and Tips on How to Prevent Them[^]


              Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

              M Offline
              M Offline
              Mahmood Ilyas
              wrote on last edited by
              #6

              thank you every one for taking interest in my query muhammad mahmood ilyas

              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