How do you insert a row at a time?
-
Hello, I have a filled a data set and would like to insert data from that dataset to a different table then the dataset was filled with, is there a way to do it a row at a time? If so does anyone have an example?:confused: Thank you, Santana
Would you elaborate more? If I am correct, then this is what you want to happen: dataadapter.fill(dataset,"Table1") 'do inserts into the dataset 'now you want all the inserted rows to be saved to Table2! True? 'If you are using update command on dataadapter, then you would be able to only save the rows to Table1 dataadapter.update(dataset) 'this will save rows to Table1 if you want these rows to be saved into another table (Table2) then create another dataadapter + dataset for that table, copy dataset1 to dataset2 and then call update on dataadapter2. let me know. Web reading made easy - http://www.xemantex.com
-
Would you elaborate more? If I am correct, then this is what you want to happen: dataadapter.fill(dataset,"Table1") 'do inserts into the dataset 'now you want all the inserted rows to be saved to Table2! True? 'If you are using update command on dataadapter, then you would be able to only save the rows to Table1 dataadapter.update(dataset) 'this will save rows to Table1 if you want these rows to be saved into another table (Table2) then create another dataadapter + dataset for that table, copy dataset1 to dataset2 and then call update on dataadapter2. let me know. Web reading made easy - http://www.xemantex.com
You can use a command object to update the rows in Dataset to the second Table in database. 'assume connString = Your connection string Dim cn as new OledbConnection(connString) Dim cmd as new OledbCommand cmd.Connection = cn cn.Open dim i as integer For i=0 to DataSet1.Tables(0).Rows.Count-1 cmd.CommandText = "INSERT INTO Table2 (Col1,Col2,Col3,..) VALUES (DataSet1.Tables(0).Rows(i).Item(1),DataSet1.Tables(0).Rows(i).Item(2),DataSet1.Tables(0).Rows(i).Item(3)....) cmd.ExecuteNonQuery Next cn.Close cmd.Dispose cn.Dispose "I think there is a world market for maybe 5 computers" Thomas Watson, chairman of IBM, 1943 "There is no reason anyone would want a computer in their home" Ken Olson, chairman & founder of Digital equipment, 1977 "This 'telephone' has too many shortcomings to be seriously considered as a means of communication. The device is ingerently of no value to us." Western Union internal memo, 1876 "640 K ought to be enough for anybody." Bill Gates, 1981 "Computers in the future may
-
Hello, I have a filled a data set and would like to insert data from that dataset to a different table then the dataset was filled with, is there a way to do it a row at a time? If so does anyone have an example?:confused: Thank you, Santana
try executing an SQL command using a command object. loop through the records in the dataset dim x as integer dim KKK as new oledbcommand kkk.connection = 'write you connection here kkk.connection.open ' if the connection is closed for x = 0 to dataset1.tables.rows.count - 1 kkk.executenonquery("Insert into TABLENAME (field1,field2,field3) values (" & dataset1.tables(x)("field1") & "," & dataset1.tables(x)("field2") & "," & dataset1.tables(x)("field3") & ")") next kkk.conection.close ' just close the connection - Casting More!! May elune shine upon you!