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. A problem in insert command?

A problem in insert command?

Scheduled Pinned Locked Moved ASP.NET
helpquestion
6 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.
  • S Offline
    S Offline
    SherKar
    wrote on last edited by
    #1

    hi , i have a problem in the insert command using oledbdataadapter when i use it it give me an error saying syntax error in insert into can any one suggest an idea plz thx

    C 1 Reply Last reply
    0
    • S SherKar

      hi , i have a problem in the insert command using oledbdataadapter when i use it it give me an error saying syntax error in insert into can any one suggest an idea plz thx

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

      I suggest you post the command so that we can see what it is in order to help you find your syntax error. To find a syntax error in a command, one must first see what the command is.


      Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

      S 2 Replies Last reply
      0
      • C Colin Angus Mackay

        I suggest you post the command so that we can see what it is in order to help you find your syntax error. To find a syntax error in a command, one must first see what the command is.


        Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

        S Offline
        S Offline
        SherKar
        wrote on last edited by
        #3

        thx for ur concern and i'll send the code asap as it is not available now for me

        1 Reply Last reply
        0
        • C Colin Angus Mackay

          I suggest you post the command so that we can see what it is in order to help you find your syntax error. To find a syntax error in a command, one must first see what the command is.


          Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

          S Offline
          S Offline
          SherKar
          wrote on last edited by
          #4

          hi, here is the code i told u about oleDbConnection1.Open(); int ActiveState=0; string Date=DateTime.Now.ToString(); string InsNew="insert into users(UserName,Password,FirstName,LastName,count,Email,StreetAddress,City,Country,Active,RegisterDate) values('"+TextBox3.Text+"','"+TxtBxPass.Text+"','"+TxtBxName.Text+"','"+TxtBxLName.Text+"','"+TxtBxYears.Text+"','"+TxtBXMail.Text+"','"+TxtBxAdd.Text+"','"+TxtBxCity.Text+"','"+TxtBxNow.Text+"','"+ActiveState+"','"+Date+"');"; oleDbDataAdapter2.InsertCommand.CommandText=InsNew; oleDbDataAdapter2.InsertCommand.ExecuteNonQuery(); oleDbConnection1.Close();

          C V 2 Replies Last reply
          0
          • S SherKar

            hi, here is the code i told u about oleDbConnection1.Open(); int ActiveState=0; string Date=DateTime.Now.ToString(); string InsNew="insert into users(UserName,Password,FirstName,LastName,count,Email,StreetAddress,City,Country,Active,RegisterDate) values('"+TextBox3.Text+"','"+TxtBxPass.Text+"','"+TxtBxName.Text+"','"+TxtBxLName.Text+"','"+TxtBxYears.Text+"','"+TxtBXMail.Text+"','"+TxtBxAdd.Text+"','"+TxtBxCity.Text+"','"+TxtBxNow.Text+"','"+ActiveState+"','"+Date+"');"; oleDbDataAdapter2.InsertCommand.CommandText=InsNew; oleDbDataAdapter2.InsertCommand.ExecuteNonQuery(); oleDbConnection1.Close();

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

            A number of things. 1. What does InsNew actually evaluate to? 2. :omg: You are storing the password as clear text in the database! 3. Learn a bit about SQL Injection attacks.[^] (The link discusses SQL Server, but the arguments are valid for all databases) If you use parameterised queries, .NET will do lots of work for you. e.g. you can pass a DateTime directly to the Parameter and it will get converted correctly for the database. What you have here may not have formatted the data correctly. Also, if you don't mind my saying, you should stick to one convention for naming variables. TextBox3, TxtBxPass, TxtBXMail - I'd have a hard time working out what to type if I had to maintain this. Using the + operator to concatenate strings is also inefficient. You should consider using a System.Text.StringBuilder for lots of concatenations, or string.Concat for a smaller number. I did some tests a year or so back and found that string.Concat was good for upto a half dozen strings, and StringBuilder was better for more than that.


            Do you want to know more? Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

            1 Reply Last reply
            0
            • S SherKar

              hi, here is the code i told u about oleDbConnection1.Open(); int ActiveState=0; string Date=DateTime.Now.ToString(); string InsNew="insert into users(UserName,Password,FirstName,LastName,count,Email,StreetAddress,City,Country,Active,RegisterDate) values('"+TextBox3.Text+"','"+TxtBxPass.Text+"','"+TxtBxName.Text+"','"+TxtBxLName.Text+"','"+TxtBxYears.Text+"','"+TxtBXMail.Text+"','"+TxtBxAdd.Text+"','"+TxtBxCity.Text+"','"+TxtBxNow.Text+"','"+ActiveState+"','"+Date+"');"; oleDbDataAdapter2.InsertCommand.CommandText=InsNew; oleDbDataAdapter2.InsertCommand.ExecuteNonQuery(); oleDbConnection1.Close();

              V Offline
              V Offline
              V 0
              wrote on last edited by
              #6

              If you get an error on the query it means the string itself is wrong. It could be the ';' at the end. try: string InsNew="insert into users(UserName,Password,FirstName,LastName,count,Email,StreetAddress,City,Country,Active,RegisterDate) values('"+TextBox3.Text+"','"+TxtBxPass.Text+"','"+TxtBxName.Text+"','"+TxtBxLName.Text+"','"+TxtBxYears.Text+"','"+TxtBXMail.Text+"','"+TxtBxAdd.Text+"','"+TxtBxCity.Text+"','"+TxtBxNow.Text+"','"+ActiveState+"','"+Date+"')"; but it could also be a "'" character. I build my queries like this also, but it often misses some detail, my advise is: debug the code and copy the query (via quickwatch or something) then paste the query in the sql editor of your database and see what happens. Here you can 'debug' your query. adjust your string in code and it should work. Keep in mind that databases have different syntax. eg. Sybase is case sensitive and Oracle is not. Good luck. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

              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