Database cannot Update unable to find TableMapping

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gobblegob
    New Member
    • Dec 2007
    • 133

    Database cannot Update unable to find TableMapping

    Hello All,
    I am getting an error trying to update datagridview1 , what i am trying to do is search for an item (BarCode.text) and then display the results to datagridview1 but i just cannot manage to do it , please help me i have been trying for days :(

    here is what i have this code is extremely crappy as i have read lots of tutorials and searches....

    Code:
    Imports System.Data.OleDb
    
    
    Public Class ServiceCompletedForm
        Dim connStr As String
        Dim conn As New OleDbConnection
        Dim da As New OleDbDataAdapter
        Dim ds As DataSet = New DataSet
        Dim cnString As String
        Dim sqlQRY As String
        Dim myCmd As New OleDbCommand
        Dim myDR As OleDbDataReader
        Dim strSQL As String
    
    
        Private Sub ServiceCompletedForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            
            DataGridView1.Columns.Add("BarCode", "Item Barcode")
        End Sub
    
        Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
            da.Update(ds, "ServiceCompleted")
        End Sub
    
        Private Sub SearchBarcodeDELETE()
            cnString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=..\data\Northwind.mdb"
            sqlQRY = "SELECT * FROM ServiceCompleted " 'WHERE BarCode'"
            conn = New OleDbConnection(cnString)
            Try
                conn.Open()
                da = New OleDbDataAdapter(sqlQRY, conn)
                'create command builder
                Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(da)
                'fill dataset
                da.Fill(ds, "ServiceCompleted")
                DataGridView1.DataSource = ds
                DataGridView1.DataMember = "ServiceCompleted"
            Catch ex As OleDbException
                MsgBox(ex.ToString)
            Finally
                ' Close connection
                conn.Close()
            End Try
        End Sub
        Function IsConnected() As Boolean
            Try
                'Checks first if already connected to database,if connected, it will be disconnected.
                If conn.State = ConnectionState.Open Then conn.Close()
                conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=..\data\Northwind.mdb"
                conn.Open()
                IsConnected = True
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Function
        Public Function KeyAscii(ByVal UserKeyArgument As KeyPressEventArgs) As Short
            KeyAscii = Asc(UserKeyArgument.KeyChar)
    
        End Function
        Sub SearchBarcode(ByVal Barcode As String)
            Try
                If IsConnected() = True Then
                    'Queries to database
    
                    strSQL = "SELECT * FROM servicecompleted WHERE BarCode = '" + Barcode + "' "
    
                    myCmd.CommandText = strSQL
                    myCmd.Connection = conn
                    da.SelectCommand = myCmd
                    myDR = myCmd.ExecuteReader()
    
                    'Display results to table
    
                    While (myDR.Read())
    
                        DataGridView1.Rows.Add(myDR("BarCode")) ', myDR("Description"), myDR("Location"), myDR("Building_Number"), myDR("Test_Tag_Interval"))
    
                    End While
                End If
            Catch ex As Exception
                MsgBox(ex.Message, , "SearchBarcode")
            End Try
            conn.Close()
        End Sub
    
        Private Sub txtBarcode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtBarcode.KeyPress
            If Me.KeyAscii(e) = 13 Then
                If IsConnected() = True Then Call SearchBarcode(txtBarcode.Text)
                e.Handled = True
            End If
        End Sub
    
    
    End Class
Working...