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. access insert instruction problem

access insert instruction problem

Scheduled Pinned Locked Moved C#
help
8 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.
  • D Offline
    D Offline
    dinosors
    wrote on last edited by
    #1

    i don't know what to do really i've seen the code 100 times and it seem right so if anyone can help....this's the code public void ajout_dossier_image(string dossier,string matr) { if (Directory.Exists(dossier)) { try { scanDirectory(dossier, "*.jpg", System.IO.SearchOption.TopDirectoryOnly); String selectedImage = selectedImg; if (imgList == null) return; foreach (String img in imgList) {ajout_image_seul(img, matr);} } catch (Exception exe) { MessageBox.Show("erreur du dossier de l'image");} } } public void ajout_image_seul(string nom_img,string matr) { try { string date = "01/01/2005";//Convert.ToString(DateTime.Now) string conStr = @"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=DermatoSoft_DB.mdb"; dataGridView1.DataSource = null; ds = new DataSet(); conn = new OleDbConnection(conStr); command = conn.CreateCommand(); conn.Open(); command.CommandText = "INSERT INTO Image (Numero_Patients,Nom_Image,Date_Image," +"Commentaire_Image) VALUES (" + matr + ",'" + nom_img + "','" + date + "','exemple commentaire')"; adapter = new OleDbDataAdapter(command); adapter.Fill(ds); conn.Close(); } catch (Exception exe) { MessageBox.Show("erreur dans l'ajout de l'image"); } } thanks

    M 1 Reply Last reply
    0
    • D dinosors

      i don't know what to do really i've seen the code 100 times and it seem right so if anyone can help....this's the code public void ajout_dossier_image(string dossier,string matr) { if (Directory.Exists(dossier)) { try { scanDirectory(dossier, "*.jpg", System.IO.SearchOption.TopDirectoryOnly); String selectedImage = selectedImg; if (imgList == null) return; foreach (String img in imgList) {ajout_image_seul(img, matr);} } catch (Exception exe) { MessageBox.Show("erreur du dossier de l'image");} } } public void ajout_image_seul(string nom_img,string matr) { try { string date = "01/01/2005";//Convert.ToString(DateTime.Now) string conStr = @"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=DermatoSoft_DB.mdb"; dataGridView1.DataSource = null; ds = new DataSet(); conn = new OleDbConnection(conStr); command = conn.CreateCommand(); conn.Open(); command.CommandText = "INSERT INTO Image (Numero_Patients,Nom_Image,Date_Image," +"Commentaire_Image) VALUES (" + matr + ",'" + nom_img + "','" + date + "','exemple commentaire')"; adapter = new OleDbDataAdapter(command); adapter.Fill(ds); conn.Close(); } catch (Exception exe) { MessageBox.Show("erreur dans l'ajout de l'image"); } } thanks

      M Offline
      M Offline
      Mark Greenwood
      wrote on last edited by
      #2

      What's happening when you run it? If your getting an error what is it? I think part of the problem is using the adapter.Fill method - I'm pretty sure that you need to use the Update method and also I'm not sure yoy sepcify a command text for the dataset - I thought you used an InsertCommand and calling update called the appropriate Commands with the change rows in the Dataset, and likewise the appropriate Update and Delete commands - been a while though so I could be wrong there - I'll look it up and let you know.....

      D M 2 Replies Last reply
      0
      • M Mark Greenwood

        What's happening when you run it? If your getting an error what is it? I think part of the problem is using the adapter.Fill method - I'm pretty sure that you need to use the Update method and also I'm not sure yoy sepcify a command text for the dataset - I thought you used an InsertCommand and calling update called the appropriate Commands with the change rows in the Dataset, and likewise the appropriate Update and Delete commands - been a while though so I could be wrong there - I'll look it up and let you know.....

        D Offline
        D Offline
        dinosors
        wrote on last edited by
        #3

        my problem is that i used this command in other part and i'm sure that the command run the error is that he cant make the instruction insert into that there's an error in type

        1 Reply Last reply
        0
        • M Mark Greenwood

          What's happening when you run it? If your getting an error what is it? I think part of the problem is using the adapter.Fill method - I'm pretty sure that you need to use the Update method and also I'm not sure yoy sepcify a command text for the dataset - I thought you used an InsertCommand and calling update called the appropriate Commands with the change rows in the Dataset, and likewise the appropriate Update and Delete commands - been a while though so I could be wrong there - I'll look it up and let you know.....

          M Offline
          M Offline
          Mark Greenwood
          wrote on last edited by
          #4

          Well I was right in the first instance - if you look at the constructor for the OleDbDataAdapter - the command query which you pass in is for the SELECT command ONLY - so it's not going to take care of what you are trying to achieve here - you need to create an InsertCommand and then call update - that should fix it (maybe!)

          D 1 Reply Last reply
          0
          • M Mark Greenwood

            Well I was right in the first instance - if you look at the constructor for the OleDbDataAdapter - the command query which you pass in is for the SELECT command ONLY - so it's not going to take care of what you are trying to achieve here - you need to create an InsertCommand and then call update - that should fix it (maybe!)

            D Offline
            D Offline
            dinosors
            wrote on last edited by
            #5

            i know the problem is that he don't wanna connect to the table image that i added but for the first table patient he can can connect this thing gonna make me crazy so please can you tell me why csharp can access to an access table and not another and the two are in the same file so please help

            M 1 Reply Last reply
            0
            • D dinosors

              i know the problem is that he don't wanna connect to the table image that i added but for the first table patient he can can connect this thing gonna make me crazy so please can you tell me why csharp can access to an access table and not another and the two are in the same file so please help

              M Offline
              M Offline
              Mark Greenwood
              wrote on last edited by
              #6

              Thats's not the problem as far as I can see - sorry I'm struggling a bit with your english to understand what you are saying, but I think your issue is that the connection is fine - it's what you are trying to do with it is wrong. You can't use an INSERT (SQL) statement as a SelectCommand on the adapter and you can't use the Fill method on the adapter to call the InsertCommand - you have to use the Update method instead. Perhaps you can put up the error and maybe that might cast some more light - but it looks as though it's just an issue with using the adapter incorrectly...

              D 1 Reply Last reply
              0
              • M Mark Greenwood

                Thats's not the problem as far as I can see - sorry I'm struggling a bit with your english to understand what you are saying, but I think your issue is that the connection is fine - it's what you are trying to do with it is wrong. You can't use an INSERT (SQL) statement as a SelectCommand on the adapter and you can't use the Fill method on the adapter to call the InsertCommand - you have to use the Update method instead. Perhaps you can put up the error and maybe that might cast some more light - but it looks as though it's just an issue with using the adapter incorrectly...

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

                i tryed "select * from image" and they don't work :confused: and i tryed "select * from patients" and they work :doh: and the two table are in the same file named data_base.mdb :omg: thanks anyway

                M 1 Reply Last reply
                0
                • D dinosors

                  i tryed "select * from image" and they don't work :confused: and i tryed "select * from patients" and they work :doh: and the two table are in the same file named data_base.mdb :omg: thanks anyway

                  M Offline
                  M Offline
                  Mark Greenwood
                  wrote on last edited by
                  #8

                  Hmmm ok that is strange, One thing that can occue on a SQL database is that case sensitivity can be on which means that a table called Image will not be found if you look for a table called image - no idea if that applies to an access database - but I guess it's worth a try?

                  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