insert changes doesn't show on database OleDb
Hello, well the problem i'm having is with the actual insertion of the data, the code actually notes when I try to enter a duplicate id which is idNombre, but if I do insert a new row, and I try to do it the first time it does it properly but the second time I try to add the same values the program does notes that the first value was added thus making the 9998 unavailable, producing an error the thing is. when i close the program no values were actually added to the access database. I'm new to .net development but i think that the problem might be with the database or the datasource config idk :P Notice that when i do insert the data via a query in the database explorer, it works and if I try that same statement in runtime it is not able to save it into the database, it adds it but just for runtime i think :P i tried to use params but it threw me an data uncompatible error i dont remember clearly haha ;p, is it only possible to insert into the database via params?? :p i would be grateful with ur help :D String connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/ControlHol.mdb"; String cantidad = this.cantidad_txt.Text; String fecha = this.feacha_dtp.Text; String numFactura = this.numFact_txt.Text; String numArticulo = this.NumArticulo_txt.Text; String numCaja = this.NumCaja_txt.Text; String numInicio = this.numInicio_txt.Text; String numFin = this.numFinal_txt.Text; String total = this.total_txt.Text; String insertSQL = "INSERT INTO Detalle (Idnombre, IdDetalle, Cantidad, Fecha, N_de_Factura, N_de_Articulo, N_De_Caja, NStart, NEnd, TOTAL)" + "VALUES(" + idNombre + ",9998," + cantidad + ",#" + fecha + "#," + numFactura + "," + numArticulo + "," + numCaja + ",'" + numInicio + "','" + numFin + "'," + total + ")"; using (OleDbConnection connection = new OleDbConnection(connectionString)) { // The insertSQL string contains a SQL statement that // inserts a new row in the source table. OleDbCommand command = new OleDbCommand(insertSQL); // Set the Connection to the new OleDbConnection. command.Connection = connection; // Open the connection and execute the insert command. try { connection.Open(); command.ExecuteNonQuery(); Console.WriteLine("Exito"); } catch (Exception ex) { Console.WriteLine(ex.Message); } // The connection is automatically closed when the // code exits the using block. connection.Close(); command.Dispose(); } Saludos Gracias :P
November 29th, 2010 1:51pm

Hi, it must be conflicting with the ID (idNombre). I am not sure why you posted this in the SSIS section of the MSDN Forums. You have also did not mention the error you are getting. To be able to insert the identity values you need to either disable it or do a T-SQL like: SET IDENTITY_INSERT MyTable ON INSERT MyTable(TheIdentity, TheValue) VALUES (1, 'First Data Row') SET IDENTITY_INSERT MyTable OFF Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
November 29th, 2010 2:19pm

well about where i post it I didn't really look into where I posted it, like this ask a question thing appeared and I just posted it, i'll look into it nextime sorry :( I'm not getting any errors, the thing is that after I insert the values, it appears that the insertion it's only reflected while on runtime, and after the program stops I dont see the inserted values during runtime reflected on the database, and the idnombre it's from a foreign table :D the idDetalle is set to 9998, to get a quick glance if the value was actually inserted, i'm just trying to insert this one value, idk if u could help me :P thanks a lot for your help or any suggestions :D
November 29th, 2010 7:11pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics