Question Deleting records from a LstBox and dat file and setting reminders to date in dat file

Joined
Aug 2, 2010
Messages
3
Location
NSW, Australia
Programming Experience
Beginner
I am creating a program that allows a person to enter details about their farm, stock, and machinery in order to electronically keep track of all of the information. I have created the forms and done all the coding for the data entry, and now what I would like to do is allow the user to delete a single record from the .dat file. I am able to delete it from the LstBox (using a "Delete Entry" btn coded simply with
VB.NET:
lstvehicles.Items.RemoveAt(lstvehicles.SelectedIndex)
(using the vehicles section for examples)), but I am unsure of how to delete it from the .dat file as well, to prevent it reloading upon data change / program reload. Any suggestions?
Also I would like to be able to have a reminder come up on the program start up that gives a reminder to (in the vehicles instance)when a vehicles rego is due, the date being associated to a date that is entered into the same lstbox data using a datetimepicker.
Thanks in advance, my apologies for my limited knowledge, I'm only self taught
 
I understand where you are coming from, but I have a limited knowledge on how to create databases etc., and I am starting to run out of time to get this completed. Would you be able to help me create the database, and to add the delete and reminder functions in? Im struggling to find any useful or relevant information. The reminder function isnt critical, but the delete function is fairly so.

Any help would be greatly appreciated, thanks, Matt
 
If you're struggling to find information on data access in .NET apps then you must be using very poor keywords in your searches because there's tons of information all over the place. You might like to start with the Data Walkthroughs link in my signature. Note that that page is for .NET 4.0, but there's a .NET 3.5 link on the right-hand side.
 
Ok, so I had a dig around and came up with this;

VB.NET:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OleDbDataAdapter1.Fill(DataSet11)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Me.BindingContext(DataSet11, "table1").EndCurrentEdit()
            Me.OleDbDataAdapter1.Update(DataSet11)
            'ending current editing and updating the dataset
        Catch
        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.BindingContext(DataSet11, "table1").AddNew()
        'adding new record/row to the table
        MsgBox("Successfully Inserted")
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox1.Text = " "
        TextBox2.Text = " "
        TextBox3.Text = " "
        TextBox4.Text = " "
        TextBox5.Text = " "
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Me.BindingContext(DataSet11, "table1").Position = Me.BindingContext(DataSet11, "table1").Position - 1
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Me.BindingContext(DataSet11, "table1").Position = Me.BindingContext(DataSet11, "table1").Position + 1
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

Which I was using alongside a number of databound textboxs. I also have a DataGridView on the same form which shows the data. My problem is that, although the data can be seen correctly in the datagridview, it doesnt save the added data to the database (.mdb) file. I apologise for being a pain but any ideas on what I migth be missing?
I also have the correctly set up (well, according to the tutorial at Simple Data Binding with ADO .NET/VB .NET anyhoo, again, I may have missed something, i've been through it three times) the OleDbConnection, DataSet, and the OleDbDataAdapter, as per the tutorial.

Thanks, Matt
 
The first thing to do is to test the value returned by Update. Either it's zero, indicating that there are no changes in your DataSet that can be saved by your DataAdapter, or it's not zero, indicating that there are changes and they are saved. My guess is that it's the latter and you're simply looking in the wrong place or at the wrong time for the data. In that case, follow the first link in my signature to find out how to manage local data files.
 
Back
Top