AboutSyed Rizwan Muhammad Rizvi Expertise I can answers questions regarding web based and desktop based programming in VB.Net. Which can include SOAP, XML, Custom Controls, COM Interoperability etc.
Experience Have been working in this specific area for last 2 years previously I was a VB 6 Developer with experties in other languages as well. Total 10 years of programming experience.
Question hi i been working on creating searching the access database for awhile finely got it to work the problem i am having now is that i cant update the database i am using vb.net 2003 here is the code for you to look at for me thank you.
Imports System.Data.OleDb
Friend Class Form1
Inherits System.Windows.Forms.Form
'Declare a variable of type DataView named _ContactsDataView.
Dim _ContactsDataView As DataView
'Declare a variable of type CurrencyManager named _ContactsCurrencyManager.
Dim _ContactsCurrencyManager As CurrencyManager
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.InitializeDataGrid()
End Sub
Public Sub InitializeDataGrid()
' Connect to Access play database.
Dim playOleDbConnection As New OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source = play.mdb;")
Dim ContactsDataAdapter As New OleDbDataAdapter("SELECT * FROM Contacts", playOleDbConnection)
Dim ToyDataSet As New DataSet
' Pull customer records.
OleDbDataAdapter.Fill(ToyDataSet, "Contacts")
' Assign Contacts DataTable to _ContactsDataView.
_ContactsDataView = New DataView(ToyDataSet.Tables("Contacts"))
' Assign the BindingContext of _ContactssDataView to _ContactsCurrencyManager.
_ContactsCurrencyManager = CType(Me.BindingContext(_ContactsDataView), CurrencyManager)
' Assign _ContactsDataView to DataGrid1 DataSource.
DataGrid1.DataSource = _ContactsDataView
_ContactsDataView.Sort = "ContactID"
End Sub
Private Sub FindButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindButton.Click
' Find the contact.
Dim contactID As Integer
' Call the _ContactsDataView's Find method passing
' in the ContactID provided by the user.
contactID = _ContactsDataView.Find(FindTextBox.Text)
' If customerID > 0 a customer was found..
If contactID >= 0 Then
_ContactsCurrencyManager.Position = contactID
Else
MessageBox.Show("Customer not found.")
End If
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Try
OleDbDataAdapter.Update(ToyDataSet)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Answer Three Problems that I can see immediately:
1. ToyDataSet is not Global so its not accessible inside btnUpdate_Click.
2. You need to update the database using OleDbDataAdapter's instance/object not using Class itself.
3. I dont see you specifing any update command with the data-adaptor.