Lowyat.NET Forums

Welcome Guest ( Log In | Register )

LYN wins Intel-Lenovo-Tangs Blogathon challenge. Thank you everybody!
 
RSS feedBump TopicClosed TopicStart new topicStart Poll

Outline · [ Standard ] · Linear+

> problems with vb2005..with microsoft access (VB)

deora
post Jul 2 2009, 07:53 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #1


Getting Started
**

Group: Junior Member
Posts: 215
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Mar 2008





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

here's my form
Attached Image


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 sweat.gif




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



Added on July 4, 2009, 12:50 amcan someone help please...

This post has been edited by deora: Jul 4 2009, 12:50 AM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Bump TopicClosed TopicTopic OptionsStart new topic
 



----debug section please ignore----
Lo-Fi Version Time is now: 23rd November 2009 - 06:18 PM
All Rights Reserved 2003-2009 Vijandren Ramadass (~living on a prayer~)