Results 1 to 4 of 4

Thread: Update a single datarow

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Update a single datarow

    I have this code:
    VB Code:
    1. oSqlDataAdapter = New SqlDataAdapter(oSqlCommand)
    2.             Dim ComBuilder As New SqlCommandBuilder(oSqlDataAdapter)
    3.  
    4.             Dim DataRows(0) As DataRow
    5.             DataRows(0) = Data
    6.             oSqlDataAdapter.Update(DataRows)
    Where Data is a DataRow.
    The SQL query of my command is:
    VB Code:
    1. Public ReadOnly Property EditSQL() As String
    2.         Get
    3.             Dim SQL As String
    4.  
    5.             SQL = "SELECT BookingDetail.BookingKey "
    6.             SQL &= ",ISNULL(BookingDetail.AssetKey, 0) AS AssetKey "
    7.             SQL &= ",ISNULL(BookingDetail.ClientKey, 0) AS ClientKey "
    8.             SQL &= ",ISNULL(BookingDetail.ContactKey,0) AS ContactKey "
    9.             SQL &= ",ISNULL(BookingDetail.BookedFrom, getDate()) AS BookedFrom "
    10.             SQL &= ",ISNULL(BookingDetail.BookedTo, GetDate()) AS BookedTo "
    11.             SQL &= ",ISNULL(BookingDetail.LayoutKey, 0) AS LayoutKey "
    12.             SQL &= ",ISNULL(BookingDetail.Guests, 0) AS Guests "
    13.             SQL &= ",ISNULL(BookingDetail.PrepTimeBefore, 0) AS PrepTimeBefore "
    14.             SQL &= ",ISNULL(BookingDetail.PrepTimeAfter, 0) AS PrepTimeAfter "
    15.             SQL &= ",ISNULL(BookingDetail.Comments, '') AS Comments "
    16.             SQL &= ",ISNULL(BookingDetail.UpdateUserID, 0) AS UpdateUserID "
    17.             SQL &= "FROM BookingDetail "
    18.  
    19.             Return SQL
    20.         End Get
    21.     End Property
    No errors occur on the update statement, but it doesn't save to the db.

    WOka

  2. #2

  3. #3
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Re: Update a single datarow

    I believe that you need to update the dataset, not the datarow.

    VB Code:
    1. oSqlDataAdapter = New SqlDataAdapter(oSqlCommand)
    2. Dim ComBuilder As New SqlCommandBuilder(oSqlDataAdapter)
    3. Dim ds as New DataSet
    4.  
    5. oSqlDataAdapter.Fill(ds,"myTable")
    6. Dim DataRows(0) As DataRow
    7. DataRows(0) = Data
    8. oSqlDataAdapter.Update(ds,"myTable")

    I'm new at this, so it's just a guess.

  4. #4

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Update a single datarow

    Well the update of the data adapetr accepts datarows...
    plus I don't have a table with the datrow as it's been destroyed.
    I create a new datariow, and pass that back to the UI froma function.
    The table that contained this gets toasted.

    if I try to add the datarow back to another data table then I get an error saying that is already assigned to a datatable.

    Woof

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