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. Record Not Insert

Record Not Insert

Scheduled Pinned Locked Moved C#
helpsales
4 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
    mjawadkhatri
    wrote on last edited by
    #1

    please tell me Error in My Coding My Coding Is OdbcConnection conn = new OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};Dbq=D:\\Opal Agro Chemical\\OpalAgroChemical.mdb;Uid=;Pwd=;"); string Invqurey = "insert into invoice(id,date,gpno,product,customer,qty,carton,rate,amount,bilty,expdate) values('" + inid.Text + "','" + dt.Text + "','" + gpno.Text + "','" + prod.Text + "','" + cust.Text + "','" + qty.Text + "','" + carton.Text + "','" + rate.Text + "','" + amount.Text + "','" + bilty.Text + "','" + expdate.Text +"')"; OdbcCommand cmd = new OdbcCommand(Invqurey, conn); conn.Open(); MessageBox.Show(cmd.CommandText); cmd.ExecuteNonQuery(); conn.Close(); This Error Is Showing When i Insert Record System.Data.Odbc.OdbcException was unhandled Message="ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement." Source="odbcjt32.dll" ErrorCode=-2146232009 Please Help Me Thanks In Advance Jawad Khatri

    OriginalGriffO T 2 Replies Last reply
    0
    • M mjawadkhatri

      please tell me Error in My Coding My Coding Is OdbcConnection conn = new OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};Dbq=D:\\Opal Agro Chemical\\OpalAgroChemical.mdb;Uid=;Pwd=;"); string Invqurey = "insert into invoice(id,date,gpno,product,customer,qty,carton,rate,amount,bilty,expdate) values('" + inid.Text + "','" + dt.Text + "','" + gpno.Text + "','" + prod.Text + "','" + cust.Text + "','" + qty.Text + "','" + carton.Text + "','" + rate.Text + "','" + amount.Text + "','" + bilty.Text + "','" + expdate.Text +"')"; OdbcCommand cmd = new OdbcCommand(Invqurey, conn); conn.Open(); MessageBox.Show(cmd.CommandText); cmd.ExecuteNonQuery(); conn.Close(); This Error Is Showing When i Insert Record System.Data.Odbc.OdbcException was unhandled Message="ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement." Source="odbcjt32.dll" ErrorCode=-2146232009 Please Help Me Thanks In Advance Jawad Khatri

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Get rid of the problem, and potential SQL injection attacks by using Parameterized queries:

      string Invqurey = "INSERT INTO invoice (id, date, gpno, product, customer, qty, carton, rate, amount, bilty, expdate)" +
      " VALUES (@inid, @dt, @gpno, @prod, @cust, @qty, @carton, @rate, @amount, @bilty, @expdate)";
      OdbcCommand cmd = new OdbcCommand(Invqurey, conn);
      cmd.AddWithValue("@inid", inid.Text);
      cmd.AddWithValue("@gpno", gpno.Text);
      ...

      Oh - and the standard is to use UPPERCASE for SQL keywords.

      You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      R 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Get rid of the problem, and potential SQL injection attacks by using Parameterized queries:

        string Invqurey = "INSERT INTO invoice (id, date, gpno, product, customer, qty, carton, rate, amount, bilty, expdate)" +
        " VALUES (@inid, @dt, @gpno, @prod, @cust, @qty, @carton, @rate, @amount, @bilty, @expdate)";
        OdbcCommand cmd = new OdbcCommand(Invqurey, conn);
        cmd.AddWithValue("@inid", inid.Text);
        cmd.AddWithValue("@gpno", gpno.Text);
        ...

        Oh - and the standard is to use UPPERCASE for SQL keywords.

        You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

        R Offline
        R Offline
        R Giskard Reventlov
        wrote on last edited by
        #3

        OriginalGriff wrote:

        Oh - and the standard is to use UPPERCASE for SQL keywords.

        In every code shop and software house I've been in for over 20 years the standard has always been lower case! Don't want to start an argument, just saying that the real standard is that there are no real standards...

        Tychotics: take us back to the moon "Life, for ever dying to be born afresh, for ever young and eager, will presently stand upon this earth as upon a footstool, and stretch out its realm amidst the stars." H. G. Wells

        1 Reply Last reply
        0
        • M mjawadkhatri

          please tell me Error in My Coding My Coding Is OdbcConnection conn = new OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};Dbq=D:\\Opal Agro Chemical\\OpalAgroChemical.mdb;Uid=;Pwd=;"); string Invqurey = "insert into invoice(id,date,gpno,product,customer,qty,carton,rate,amount,bilty,expdate) values('" + inid.Text + "','" + dt.Text + "','" + gpno.Text + "','" + prod.Text + "','" + cust.Text + "','" + qty.Text + "','" + carton.Text + "','" + rate.Text + "','" + amount.Text + "','" + bilty.Text + "','" + expdate.Text +"')"; OdbcCommand cmd = new OdbcCommand(Invqurey, conn); conn.Open(); MessageBox.Show(cmd.CommandText); cmd.ExecuteNonQuery(); conn.Close(); This Error Is Showing When i Insert Record System.Data.Odbc.OdbcException was unhandled Message="ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement." Source="odbcjt32.dll" ErrorCode=-2146232009 Please Help Me Thanks In Advance Jawad Khatri

          T Offline
          T Offline
          Thomas Krojer
          wrote on last edited by
          #4

          get the content onv Invqurey, an ask then the question in the SQL forum.

          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