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. Database & SysAdmin
  3. Database
  4. how 2 write Querry in C#

how 2 write Querry in C#

Scheduled Pinned Locked Moved Database
csharp
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.
  • C Offline
    C Offline
    cshivaprasad
    wrote on last edited by
    #1

    Can any one make it syntactically correct 2 use inside c# "SELECT Word,Category,Number,Gender,Person,Degree,ObjectType,Tense,Aspect,Mood,Comp1,Comp2,Comp3,Theta1,Theta2,Theta3 FROM HindiLex,Attributes,SubCategoryFrames,ThematicFrames where HindiLex.Word = N'"+word+"'" and HindiLex.AttrNo = "Attributes.AttrNo%" and HindiLex.LexSCFNo = SubCategoryFrames.LexSCFNo and HindiLex.ThemSCFNo = ThematicFrames.ThemSCFNo";

    C C 2 Replies Last reply
    0
    • C cshivaprasad

      Can any one make it syntactically correct 2 use inside c# "SELECT Word,Category,Number,Gender,Person,Degree,ObjectType,Tense,Aspect,Mood,Comp1,Comp2,Comp3,Theta1,Theta2,Theta3 FROM HindiLex,Attributes,SubCategoryFrames,ThematicFrames where HindiLex.Word = N'"+word+"'" and HindiLex.AttrNo = "Attributes.AttrNo%" and HindiLex.LexSCFNo = SubCategoryFrames.LexSCFNo and HindiLex.ThemSCFNo = ThematicFrames.ThemSCFNo";

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

      You can't write a query in C#, all you can do is pass the query from C# to your database. What database are you using ? You should read some of the articles on this site, I'm sure there's one for connecting to whatever DB you use. Christian Graus - Microsoft MVP - C++

      C 1 Reply Last reply
      0
      • C Christian Graus

        You can't write a query in C#, all you can do is pass the query from C# to your database. What database are you using ? You should read some of the articles on this site, I'm sure there's one for connecting to whatever DB you use. Christian Graus - Microsoft MVP - C++

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

        Yes U R Right, I wanna pass Query fm C#. so for passing the query string syntax changes inside c#, is nt it... i want that string syntax. i am using SQL sERVER AS DB. If possible pls modify to make it syntactically correct, thank U

        C 1 Reply Last reply
        0
        • C cshivaprasad

          Yes U R Right, I wanna pass Query fm C#. so for passing the query string syntax changes inside c#, is nt it... i want that string syntax. i am using SQL sERVER AS DB. If possible pls modify to make it syntactically correct, thank U

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

          cshivaprasad wrote:

          so for passing the query string syntax changes inside c#, is nt it...

          Nope - C# is just calling SQL Server, so the syntax has to be what SQL Server expects. If you put a @ at the front of your string, as in string s = @"this is the string"; then the only special character is to use "" for ". Otherwise, it's verbatim.

          cshivaprasad wrote:

          If possible pls modify to make it syntactically correct, thank U

          What is the reason for htis question ? Have you connected to the DB and had an error about syntax ? Where are you putting this SQL ? Are you creatings Connection objects and so on and connecting to SQL Server ? Have you tried your SQL inside SQL Server to make sure it's good there ? Christian Graus - Microsoft MVP - C++

          1 Reply Last reply
          0
          • C cshivaprasad

            Can any one make it syntactically correct 2 use inside c# "SELECT Word,Category,Number,Gender,Person,Degree,ObjectType,Tense,Aspect,Mood,Comp1,Comp2,Comp3,Theta1,Theta2,Theta3 FROM HindiLex,Attributes,SubCategoryFrames,ThematicFrames where HindiLex.Word = N'"+word+"'" and HindiLex.AttrNo = "Attributes.AttrNo%" and HindiLex.LexSCFNo = SubCategoryFrames.LexSCFNo and HindiLex.ThemSCFNo = ThematicFrames.ThemSCFNo";

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

            This code is susceptible to SQL Injection Attacks. You inject a variable called word into the query string. You should use parameters instead. See SQL Injection Attacks and Tips on How to Prevent Them[^] it will give you information on how to call SQL from C#


            "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

            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