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