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. Web Development
  3. ASP.NET
  4. urgent

urgent

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netdatabasesysadmin
7 Posts 7 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.
  • J Offline
    J Offline
    jai 123
    wrote on last edited by
    #1

    hi please help me i have designed a form in asp.net with sqlserver. India US UK Canada SqlConnection con=new SqlConnection("database=anand;server=sdiserver;uid=sa;pwd=sa"); con.Open(); SqlCommand cmd=new SqlCommand("Insert into jai(name,age,gender,conntry)values('"+Txtname.Text+"','"+Txtage.Text+"','"+txtgender.Text+"','"+coun+"'",con); cmd.ExecuteNonQuery(); con.Close(); i am getting this error Incorrect syntax near 'India' please help me

    jai prakash

    I C L N V 5 Replies Last reply
    0
    • J jai 123

      hi please help me i have designed a form in asp.net with sqlserver. India US UK Canada SqlConnection con=new SqlConnection("database=anand;server=sdiserver;uid=sa;pwd=sa"); con.Open(); SqlCommand cmd=new SqlCommand("Insert into jai(name,age,gender,conntry)values('"+Txtname.Text+"','"+Txtage.Text+"','"+txtgender.Text+"','"+coun+"'",con); cmd.ExecuteNonQuery(); con.Close(); i am getting this error Incorrect syntax near 'India' please help me

      jai prakash

      I Offline
      I Offline
      Imran Khan Pathan
      wrote on last edited by
      #2

      Missing to enclose query ")" after coun Best Regard Pathan -- modified at 5:30 Friday 24th August, 2007

      ---------------------------------------------------

      1 Reply Last reply
      0
      • J jai 123

        hi please help me i have designed a form in asp.net with sqlserver. India US UK Canada SqlConnection con=new SqlConnection("database=anand;server=sdiserver;uid=sa;pwd=sa"); con.Open(); SqlCommand cmd=new SqlCommand("Insert into jai(name,age,gender,conntry)values('"+Txtname.Text+"','"+Txtage.Text+"','"+txtgender.Text+"','"+coun+"'",con); cmd.ExecuteNonQuery(); con.Close(); i am getting this error Incorrect syntax near 'India' please help me

        jai prakash

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

        u can take the suggestion given by the previous thread winnie

        1 Reply Last reply
        0
        • J jai 123

          hi please help me i have designed a form in asp.net with sqlserver. India US UK Canada SqlConnection con=new SqlConnection("database=anand;server=sdiserver;uid=sa;pwd=sa"); con.Open(); SqlCommand cmd=new SqlCommand("Insert into jai(name,age,gender,conntry)values('"+Txtname.Text+"','"+Txtage.Text+"','"+txtgender.Text+"','"+coun+"'",con); cmd.ExecuteNonQuery(); con.Close(); i am getting this error Incorrect syntax near 'India' please help me

          jai prakash

          L Offline
          L Offline
          laddie 0
          wrote on last edited by
          #4

          Hai, Just my small suggestion..This is a regular problem when using the SQl query in this way and is considered a bad programming practice.. You can make it better and free from error by doing it like below. SqlConenction con = new SqlConnection("database=anand;server=sdiserver;uid=sa;pwd=sa"); con.Open(); SqlCommand cmd = new SqlCommand("insert into jai(name,age,genter,country) values(@name,@age,@genter,@country)",con); cmd.Parameters.Add("@name",SqlDbType.Char).Value = Txtname.Text; cmd.Parameters.Add("@age",SqlDbType.Int).Value = int.Parse(Txtage.Text); cmd.Parameters.Add("@genter",SqlDbType.Char).Value = txtgender.Text cmd.Parameters.Add("@country",SqlDbType.Char).Value = coun; cmd.ExecuteNonQuery(); This will help you a lot when doing queries with large number of parameters. Hope this helps Laddie

          1 Reply Last reply
          0
          • J jai 123

            hi please help me i have designed a form in asp.net with sqlserver. India US UK Canada SqlConnection con=new SqlConnection("database=anand;server=sdiserver;uid=sa;pwd=sa"); con.Open(); SqlCommand cmd=new SqlCommand("Insert into jai(name,age,gender,conntry)values('"+Txtname.Text+"','"+Txtage.Text+"','"+txtgender.Text+"','"+coun+"'",con); cmd.ExecuteNonQuery(); con.Close(); i am getting this error Incorrect syntax near 'India' please help me

            jai prakash

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            jai aswitha wrote:

            SqlCommand cmd=new SqlCommand("Insert into jai(name,age,gender,conntry)values('"+Txtname.Text+"','"+Txtage.Text+"',' "+txtgender.Text+"','"+coun+"'",con); cmd.ExecuteNonQuery();

            If this example is only for some demonstration purpose, then this is ok. You can accept the suggestion given by first poster. But if you are using this in a online server, It looks like you are very closer to SQL Injection Attacks. You should never write queries like this, use parameterized queries or stored procedures. To know regarding the attacks check this[^] excellent article.


            My Website | Ask smart questions

            1 Reply Last reply
            0
            • J jai 123

              hi please help me i have designed a form in asp.net with sqlserver. India US UK Canada SqlConnection con=new SqlConnection("database=anand;server=sdiserver;uid=sa;pwd=sa"); con.Open(); SqlCommand cmd=new SqlCommand("Insert into jai(name,age,gender,conntry)values('"+Txtname.Text+"','"+Txtage.Text+"','"+txtgender.Text+"','"+coun+"'",con); cmd.ExecuteNonQuery(); con.Close(); i am getting this error Incorrect syntax near 'India' please help me

              jai prakash

              V Offline
              V Offline
              Vasudevan Deepak Kumar
              wrote on last edited by
              #6

              Amongst all syntax and semantic errors that I would like to guide you in this query, the first and foremost to suggest you is that you should take remedial steps to solve the aggressive SQLInjection vulnerability that is blatantly visible in this code snippet.:)

              Vasudevan Deepak Kumar Personal Homepage Tech Gossips

              D 1 Reply Last reply
              0
              • V Vasudevan Deepak Kumar

                Amongst all syntax and semantic errors that I would like to guide you in this query, the first and foremost to suggest you is that you should take remedial steps to solve the aggressive SQLInjection vulnerability that is blatantly visible in this code snippet.:)

                Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                D Offline
                D Offline
                dandy72
                wrote on last edited by
                #7

                Amongst all syntax and semantic errors that I would like to guide you in this query, the first and foremost to suggest you is that you should take remedial steps to solve the aggressive SQLInjection vulnerability that is blatantly visible in this code snippet. ...not to say anything about the sa account name and password. :-D

                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