View Single Post
  #1 (permalink)  
Old 07-03-2009, 5:28 AM
wongth7 wongth7 is offline
VB.NET Forum Newbie
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Jun 2009
Posts: 7
Reputation: 0
wongth7 is on a distinguished programming path ahead
Default problems with vb2005..with microsoft access

hi guys..i have some problem with my VB program..hope u guys can help me out

in my form, there's 8 textboxes that will display data from the database, 3 button's which is '<<' '>>' and 'DELETE'


explanation on my program
---------------------------------
the ' << ' and ' >> ' button will browse through records from the database...while the "delete" button will delete the record from the database...
i have no problem browsing through the records from the database and no problem deleting the records with those buttons


but there's some minor problem..
----------------------------------------
problem 1 - when i click on the 'delete' button to delete a record, the data will still appear in the textboxes when i click on the '<<' and '>>' buttons, although the data in the database already been deleted.

problem 2 (same problem related to problem 1) - when i keep clicking on the 'delete' button to delete all the records, the program will then crash and this error message appear 'Concurrency violation: the DeleteCommand affected 0 of the expected 1 records.'..........how to avoid this??

problem 3 - if the database is empty and i log into the form and click on the '<<' , '>>' buttons, the program will then crash and this error message appear 'There is no row at position 1.' ....how to lock those button's when the database is empty or any other ways??



please show me sample codes or something as i will find it hard to understand if you just explain those logic things etc for me


here's my code....

Code:
_________________________________________________________________
Private Sub frmUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

       con.ConnectionString = "PROVIDER = Microsoft.Jet.OLEDB.4.0;Data Source = H:\Testing\Project\user.mdb"
       con.Open()
       sql = "SELECT * FROM Table1"
       da = New OleDb.OleDbDataAdapter(sql, con)
       da.Fill(ds, "Table1List")
       con.Close()
       maxrows = ds.Tables("Table1List").Rows.Count

       txtName.Text = ds.Tables("Table1List").Rows(0).Item(0)
       txtUsername.Text = ds.Tables("Table1List").Rows(0).Item(1)
       txtNickname.Text = ds.Tables("Table1List").Rows(0).Item(2)
       txtPassword.Text = ds.Tables("Table1List").Rows(0).Item(3)
       txtCity.Text = ds.Tables("Table1List").Rows(0).Item(4)
       txtAddress.Text = ds.Tables("Table1List").Rows(0).Item(5)
       txtTown.Text = ds.Tables("Table1List").Rows(0).Item(6)
       txtPostcode.Text = ds.Tables("Table1List").Rows(0).Item(7)

   End Sub

_________________________________________________________________

Public Sub navigaterecords(ByVal position As Integer)

       txtName.Text= ds.Tables("Table1List").Rows(position).Item(0)
       txtUsername.Text = ds.Tables("Table1List").Rows(position).Item(1)
       txtNickname.Text = ds.Tables("Table1List").Rows(position).Item(2)
       txtPassword.Text = ds.Tables("Table1List").Rows(position).Item(3)
       txtCity.Text = ds.Tables("Table1List").Rows(position).Item(4)
       txtAddress.Text = ds.Tables("Table1List").Rows(position).Item(5)
       txtTown.Text = ds.Tables("Table1List").Rows(position).Item(6)
       txtPostcode.Text = ds.Tables("Table1List").Rows(position).Item(7)

   End Sub

_________________________________________________________________


     Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click

       If inc <> maxrows - 1 Then
           inc = inc + 1
           navigaterecords(inc)
       Else
           MessageBox.Show("No more applications!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
       End If

   End Sub  

_________________________________________________________________


Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click

       If inc <> 0 Then
           inc = inc - 1
           navigaterecords(inc)
       Else
           MessageBox.Show("No more applications!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
       End If

   End Sub
_________________________________________________________________

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click


       con.ConnectionString = "PROVIDER = Microsoft.Jet.OLEDB.4.0;Data Source = H:\Testing\Project\user.mdb"
       con.Open()
       sql = "SELECT * FROM Table1"
       da = New OleDb.OleDbDataAdapter(sql, con)
       da.Fill(ds, "Table1List")
       con.Close()
       maxrows = ds.Tables("Table1List").Rows.Count

       Dim cb As New OleDb.OleDbCommandBuilder(da)
       Dim intresult As Integer

       intresult = MessageBox.Show("Confirm Delete?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
       If intresult = Windows.Forms.DialogResult.Yes Then
           ds.Tables("Table1List").Rows(inc).Delete()
           da.Update(ds, "Table1List")
           maxrows = maxrows - 1
           inc = 0
           navigaterecords(inc)

       End If
_________________________________________________________________
Reply With Quote