Hi.... I have a datepicker that contains an alternate key of an Access Table with a autokey primary key.

Private Sub DateTimePicker1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles DateTimePicker1.Validating

        Dim d As Date = DateTimePicker1.Value
        If d < Today Then
            MsgBox("Gelieve een datum in de toekomst te willen aangeven.")
            DateTimePicker1.Focus()
            Exit Sub
        End If
        Dim n As Integer = Me.FeestdagenTableAdapter.Fill(Me.FeestdagenDataset.Feestdagen, d)
        If n = 0 Then
            Me.FeestdagenBindingSource.AddNew()
            Me.DateTimePicker1.Value = d
            Exit Sub
        End If
    End Sub

I have a "Save" Button

Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
        Me.FeestdagenBindingSource.EndEdit()
        Me.FeestdagenTableAdapter.Update(FeestdagenDataset.Feestdagen)
        Me.FeestdagenDataset.Clear()
        Me.DateTimePicker1.Value = Today
        Me.TextBox1.Text = ""
    End Sub

Now this works fine in update mode, but in add (insert mode) the primary key is generated and the other field FD_Naam is updated alright, but FD_Datum is blank.

When I put a msgbox(me.datapicker1.value) it is set correctly when it gets in the save_click. How can I see/set what is "bound" int the Bindingsource? (I mean what would be the syntax to check what is / directly write in the form's dataset?).

Thanks for any light you could shed on this.

Recommended Answers

All 5 Replies

OK. It works now. I'm not sure what had caused my problem in the first place.

I was able to "see" the dataset using this in the immediate window :

? Me.FeestdagenDataset.Feestdagen.Rows(0)("FD_Datum").ToString

you could have set a breakpoint or used a try/catch and viewed the exception message, I have little experience with Access as for work we mainly use SQL Server 2005, you could have run a trace to see what is actually being executed on the database(If it can even be done in Access, i'm not familiar with it)

Basically what you described is what I did. I was wondering about the syntax (aka trying to find my way in the oo model labyrinth) how to get the info, not about how to use the IDE.

As is probably very obvious, I'm just starting with vb (coming from Visual Foxpro), so I'm not going to comment on my experience with using an Access database. :)

Kind Regards,

Marc

Ah I understand, VB.net doesn't really take long to get to grips with, i suppose it can be compared to riding a bike, once you know how, you'll never forget :)

- Jordan

Thanks for the words of encouragement Jordan. I can use all I can get :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.