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. i can't to insert a new row

i can't to insert a new row

Scheduled Pinned Locked Moved Database
databasexmlhelpquestionannouncement
12 Posts 2 Posters 1 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.
  • T tojamismis

    What is the syntax for your myAdapter.UpdateCommand and myAdapter.InsertCommand? Torin Blair
    'In the immortal words of Socrates - "I drank what?".'

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

    Sorry i don't understand what you mean, please can you explain me? Thanks.

    T 1 Reply Last reply
    0
    • S Sasuko

      Sorry i don't understand what you mean, please can you explain me? Thanks.

      T Offline
      T Offline
      tojamismis
      wrote on last edited by
      #4

      In order for you to be able to update or insert from your dataadapter, you need to specify an insert SQL statement in the OleDbDataAdapter.InsertCommand, and an update SQL statement in the OleDbDataAdapter.UpdateCommand. If you used the wizard to create your adapter, you probably already have these statements. In debug, or by writing out to a label on the screen, you should output both of these properties and see if their SQL Syntax is correct. This will allow you see the sql commands you are using with the database. These strings are probably also listed in the WinForms or WebForms generated code if you are using Visual Studio .NET Torin Blair
      'In the immortal words of Socrates - "I drank what?".'

      S 1 Reply Last reply
      0
      • T tojamismis

        In order for you to be able to update or insert from your dataadapter, you need to specify an insert SQL statement in the OleDbDataAdapter.InsertCommand, and an update SQL statement in the OleDbDataAdapter.UpdateCommand. If you used the wizard to create your adapter, you probably already have these statements. In debug, or by writing out to a label on the screen, you should output both of these properties and see if their SQL Syntax is correct. This will allow you see the sql commands you are using with the database. These strings are probably also listed in the WinForms or WebForms generated code if you are using Visual Studio .NET Torin Blair
        'In the immortal words of Socrates - "I drank what?".'

        S Offline
        S Offline
        Sasuko
        wrote on last edited by
        #5

        I'm a newbie can you tell me how run the wizard to create the adapter?

        T 1 Reply Last reply
        0
        • S Sasuko

          I'm a newbie can you tell me how run the wizard to create the adapter?

          T Offline
          T Offline
          tojamismis
          wrote on last edited by
          #6

          If you drag a data adapter to a form, then it will open a wizard for you. No worries you can do this the manual way. OleDbCommand cmdUpdate = new OleDbCommand(_SQLCOMMAND_); OleDbCommand cmdInsert = new OleDbCommand(_SQLCOMMAND_); myAdapter.UpdateCommand = cmdUpdate; myAdapter.InsertCommand = cmdInsert; And that's how it's done. For a more detailed explanation you can look at the .NET sdk documentation or this example from csharpcorner. http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=103[^] Torin Blair
          'In the immortal words of Socrates - "I drank what?".'

          S 1 Reply Last reply
          0
          • T tojamismis

            If you drag a data adapter to a form, then it will open a wizard for you. No worries you can do this the manual way. OleDbCommand cmdUpdate = new OleDbCommand(_SQLCOMMAND_); OleDbCommand cmdInsert = new OleDbCommand(_SQLCOMMAND_); myAdapter.UpdateCommand = cmdUpdate; myAdapter.InsertCommand = cmdInsert; And that's how it's done. For a more detailed explanation you can look at the .NET sdk documentation or this example from csharpcorner. http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=103[^] Torin Blair
            'In the immortal words of Socrates - "I drank what?".'

            S Offline
            S Offline
            Sasuko
            wrote on last edited by
            #7

            Hi, tojamismis. Thanks for the answer... Another user has wrote me this: the first problem is that your table doesn't show a primary key. Without it, .Update() won't work. Second, you, apparently, don't have an Update command associated with the DataAdapter. Third, if the Primary Key information is missing, you set the .MissingSchemaAction, but never called .FillSchema before you called .Fill In your opinion what other things have i miss?

            S T 3 Replies Last reply
            0
            • S Sasuko

              Hi, tojamismis. Thanks for the answer... Another user has wrote me this: the first problem is that your table doesn't show a primary key. Without it, .Update() won't work. Second, you, apparently, don't have an Update command associated with the DataAdapter. Third, if the Primary Key information is missing, you set the .MissingSchemaAction, but never called .FillSchema before you called .Fill In your opinion what other things have i miss?

              S Offline
              S Offline
              Sasuko
              wrote on last edited by
              #8

              Can add you directly the missing rows of code, i'm not success. :(

              T 1 Reply Last reply
              0
              • S Sasuko

                Hi, tojamismis. Thanks for the answer... Another user has wrote me this: the first problem is that your table doesn't show a primary key. Without it, .Update() won't work. Second, you, apparently, don't have an Update command associated with the DataAdapter. Third, if the Primary Key information is missing, you set the .MissingSchemaAction, but never called .FillSchema before you called .Fill In your opinion what other things have i miss?

                T Offline
                T Offline
                tojamismis
                wrote on last edited by
                #9

                I can't think of anything else. It is true that you need these additional things if you aren't using a strongly typed dataset. But that should be it. Torin Blair
                'In the immortal words of Socrates - "I drank what?".'

                1 Reply Last reply
                0
                • S Sasuko

                  Can add you directly the missing rows of code, i'm not success. :(

                  T Offline
                  T Offline
                  tojamismis
                  wrote on last edited by
                  #10

                  I don't know the structure of your tables so I can't write any of the sql statements. Torin Blair
                  'In the immortal words of Socrates - "I drank what?".'

                  S 1 Reply Last reply
                  0
                  • S Sasuko

                    Hi, tojamismis. Thanks for the answer... Another user has wrote me this: the first problem is that your table doesn't show a primary key. Without it, .Update() won't work. Second, you, apparently, don't have an Update command associated with the DataAdapter. Third, if the Primary Key information is missing, you set the .MissingSchemaAction, but never called .FillSchema before you called .Fill In your opinion what other things have i miss?

                    T Offline
                    T Offline
                    tojamismis
                    wrote on last edited by
                    #11

                    That is correct, without strongly typed datasets you should add this line right before you call myAdapter.Fill. myAdapter.FillSchema(ds, SchemaType.Source, "MyTable"); Torin Blair
                    'In the immortal words of Socrates - "I drank what?".'

                    1 Reply Last reply
                    0
                    • T tojamismis

                      I don't know the structure of your tables so I can't write any of the sql statements. Torin Blair
                      'In the immortal words of Socrates - "I drank what?".'

                      S Offline
                      S Offline
                      Sasuko
                      wrote on last edited by
                      #12

                      It is compose just by a table "myTable" with: Name: text 20 primarykey Surname: text 20 Image: OLEOBJ Byte[]

                      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