Results 1 to 8 of 8

Thread: Updating Database through dataset OleDbDataAdapter [Solved]

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2004
    Posts
    66

    Resolved Updating Database through dataset OleDbDataAdapter [Solved]

    Hi,

    I have a problem with updating my database with this code.

    VB Code:
    1. Private moDS As DataSet

    VB Code:
    1. Private Sub DataUpdate()
    2.         Dim oAdapter As OleDbDataAdapter
    3.         Dim oBuild As OleDbCommandBuilder
    4.         Dim oDR As DataRow
    5.         Dim strSQL As String
    6.         Dim strID As String
    7.         Dim strConn As String
    8.  
    9.         ' Get Primary Key From List Box
    10.         strID = CType(lstLeden.SelectedItem, PDSAListItemNumeric).ID.ToString()
    11.  
    12.         ' Find Row To Update
    13.         oDR = moDS.Tables("Gegevens").Rows.Find(CInt(strID))
    14.  
    15.         ' Begin the editing process
    16.         oDR.BeginEdit()
    17.  
    18.         ' Load new data into row
    19.         oDR("Voorletters") = txtVoorletters.Text
    20.         oDR("Tussenvoegsel") = txtTussenvoegsel.Text
    21.         oDR("Achternaam") = txtAchternaam.Text
    22.         oDR("Aanspreeknaam") = txtAanspreeknaam.Text
    23.         oDR("Geslacht") = txtGeslacht.Text
    24.         oDR("Adres") = txtAdres.Text
    25.         oDR("Postcode") = txtPostcode.Text
    26.  
    27.         ' End the editing process
    28.         oDR.EndEdit()
    29.  
    30.         Try
    31.             ' Get Connection String
    32.             strConn = ConnectionString()
    33.             ' Build SQL String
    34.             strSQL = "SELECT *, Achternaam + ', ' + Voorletters AS FullName FROM Gegevens"
    35.             ' Create New DataAdapter
    36.             oAdapter = New OleDbDataAdapter(strSQL, strConn)
    37.             ' Create CommandBuild from Adapter
    38.             ' This will build INSERT, UPDATE and DELETE SQL
    39.             oBuild = New OleDbCommandBuilder(oAdapter)
    40.  
    41.  
    42.             ' Get Update Command Object
    43.             oAdapter.UpdateCommand = oBuild.GetUpdateCommand()
    44.  
    45.             ' Submit UPDATE through Adapter
    46.             oAdapter.Update(moDS, "Gegevens")
    47.             ' Tell DataSet changes to data source are complete
    48.             moDS.AcceptChanges()
    49.  
    50.             ' Reload the list box
    51.             ListLoad()
    52.  
    53.         Catch oException As Exception
    54.             MessageBox.Show(oException.Message)
    55.  
    56.         End Try
    57.     End Sub

    When i run this piece of code it says that "Automatically Generate an SQL Statement is not supported"

    Why is that, and what can i do about it?
    Last edited by digita; Nov 22nd, 2004 at 09:02 AM.

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