Results 1 to 3 of 3

Thread: [RESOLVED] Help about save dataset to table

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Resolved [RESOLVED] Help about save dataset to table

    i want to save dataset from table (bible) to another table (tt) in access 2003 database
    this is the code i have

    vb Code:
    1. Private Sub Option1ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Option1ToolStripMenuItem.Click
    2.        
    3.         Dim sQuery As String = "SELECT Bible.BookNum, Bible.ChapterNum, Bible.VerseNum FROM BibleBookNames INNER JOIN Bible ON BibleBookNames.BookNum = Bible.BookNum WHERE (((BibleBookNames.Book)=""" & DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(0).Value.ToString & """) AND ((Bible.ChapterNum)= " & ComboBox2.Text & ") AND ((Bible.VerseNum)=" & DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(1).Value.ToString & "));"
    4.         Dim SQLQuery As New OleDbDataAdapter(sQuery, CON)
    5.         Dim dsResult As New DataSet
    6.         SQLQuery.Fill(dsResult, "tt")
    7.  
    8.         Dim sCollection As String = "Select * from tt;"
    9.         Dim daCollection As New OleDbDataAdapter(sCollection, CON)
    10.         Dim objCommandBuilder As New OleDbCommandBuilder(daCollection)
    11.         daCollection.Update(dsResult, "tt")
    12.  
    13.  
    14.     End Sub

    but nothing happen or being saved to the other table which is tt

  2. #2
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Help about save dataset to table

    No need to do that... Why take the overhead of moving the data from the database to the client and back to the database....

    This can all be done in 1 SQL statement and happen directly on the database

    Insert into TableName (FieldName1,FieldName2,....) Select Field1,Field2,.... From table

    Code:
    INSERT INTO whaterTableName (BookNummChapterNum,VerseNum) 
    SELECT Bible.BookNum, Bible.ChapterNum, Bible.VerseNum FROM BibleBookNames INNER JOIN Bible ON BibleBookNames.BookNum = Bible.BookNum WHERE (((BibleBookNames.Book)=""" & DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(0).Value.ToString & """) AND ((Bible.ChapterNum)= " & ComboBox2.Text & ") AND ((Bible.VerseNum)=" & DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(1).Value.ToString & "))
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Posts
    534

    Re: Help about save dataset to table

    thanks for help GaryMazzone
    Last edited by new1; Apr 14th, 2010 at 02:15 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width