Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2002
    Posts
    3

    Question Unanswered: VB .NET - DB Update

    Hello,

    I am new in VB .NET world and I am blocked by a little problem when trying to update a DB record.

    It seems I can't find the right way to implement a Data Adtaper and Data Set derived from a master class.
    The Data access occurs correctly, I can browse my records, but when trying to perform an update or an insert, I receive an exception fault:
    Null value not allowed.

    It seems the link isn't done correctly between my field in the form and my derivde DataSet.

    Does anyone have an exemple how it has to be programmed?

    Thanks in advance.

    Hecate.

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    What are you trying to insert/update ? Post the data definition of the table you are trying to insert/update. Be as specific as possible as to what you are updating/inserting in your code and the actual definition of the table ?

  3. #3
    Join Date
    Aug 2002
    Location
    Kampala, Uganda - East Africa
    Posts
    13

    Re: VB .NET - DB Update

    Take another look at the structure of your table which you are trying to update.
    There must be a field that you have set not to allow null values. As in, it should have data inserted into it on every instance of populating the table.
    While at the front end, no data has been availed for this field.

    The only sure test is to first make sure that you insert something for every field in the table.

  4. #4
    Join Date
    Sep 2002
    Posts
    3

    Re: VB .NET - DB Update

    The definition of my table is quiet easy:

    Id - Int - 4 - Null NOT allowed
    Desc1 - Varchar - 100 - Null Allowed
    Desc2 - Varchar - 100 - Null Allowed

    And here is the code:
    1) Update command:

    Private Sub cmdUpd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpd.Click
    Dim con As New ds_vehicle

    Me.BindingContext(loc_ds_vehicle, "cat_veh").EndCurrentEdit()
    ds = CType(loc_ds_vehicle.GetChanges, CSF.ds_vehicle)
    con.UpdateDataSource(ds)
    loc_ds_vehicle.Merge(ds)
    loc_ds_vehicle.AcceptChanges()
    End Sub

    2) DataAdapter Update defined in another module:

    Public Sub UpdateDataSource(ByVal ds As CSF.ds_vehicle)
    DbConnection.Open()

    Dim UpdatedRows As System.Data.DataSet
    Dim InsertedRows As System.Data.DataSet
    Dim DeletedRows As System.Data.DataSet

    UpdatedRows = ds.GetChanges(System.Data.DataRowState.Modified)
    InsertedRows = ds.GetChanges(System.Data.DataRowState.Added)
    DeletedRows = ds.GetChanges(System.Data.DataRowState.Deleted)

    Try
    da_vehicle.Update(UpdatedRows)
    da_vehicle.Update(InsertedRows)
    da_vehicle.Update(DeletedRows)
    Catch updateException As System.Exception
    MsgBox("Caught exception: " & updateException.Message)
    End Try

    Me.DbConnection.Close()
    End Sub

  5. #5
    Join Date
    Sep 2002
    Posts
    3

    Re: VB .NET - DB Update

    When running the program I only test by updating a field... It means each field on the form is filled in.

    Althought the error message is mentionning no Null value allowed. It's like it doesn't keep the link between the form and the dataset at the time of the update.

    Weirder... If i change a field on the form... then move to another record, and only then perform the update, I receive the same error, but changes are applied to the database.

    The Insert/update sequence doesn't work at all... even if I move back on another record before to perform the update. In all case I get the No Null Value allowed error and no change is applied to the DataBase.

    Hecate.

Posting Permissions

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