1 Replies - 956 Views - Last Post: 02 July 2014 - 01:23 PM Rate Topic: -----

#1 Dien09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 14-June 14

Column 'PlayerID' Does Not Belong To Table.

Posted 02 July 2014 - 01:07 PM

Hi, for some reason, whenever I try adding information to my database table, I get this error which states that my column 'PlayerID' does not belong to table. That is not the case because I do have a column named 'PlayerID' in my database table. My friend is also having the same problem, and we both can not figure it out. I Googled it, but I got even more confused, as almost all of the explanation is too technical and includes material that we will not cover in this class. I know you have to call the column name exactly as it appears on your database, as well as you can not have spaces because supposedly VB Studio messes up. I would appreciate any help. I don't need the correct answer, outright, as I would like to understand this error. Thanks. I accidentally posted this under VB.NET earlier, you can look at my conversation here: http://www.dreaminco...elong-to-table/


Public Class frmAdd

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        Dim dt As New DataTable
        Dim connStr As String = "provider=microsoft.jet.oledb.4.0;" &
            "data source=C:\Users\Haris\Documents\player.mdb"
        Dim sqlStr As String = "select * from player"
        Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)
        Dim i, Age, PlayerID As Integer
        Dim PlayerName, Position, TeamName, AgentName As String
     

        Dim rw As DataRow
        Dim commandbuilder As New OleDb.OleDbCommandBuilder(dataAdapter)
        'Add a new row to the player table'
        rw = dt.NewRow
        PlayerID = mtxtPlayerID.Text
        PlayerName = mtxtName.Text
        Age = mtxtAge.Text
        Position = mtxtPosition.Text
        TeamName = mtxtTeam.Text
        AgentName = mtxtAgent.Text
        rw.Item("PlayerID") = PlayerID
        rw.Item("PlayerName") = PlayerName
        rw.Item("Position") = Position
        rw.Item("Age") = Age
        rw.Item("Team") = TeamName
        rw.Item("Agent") = AgentName
        Try
            dt.Rows.Add(rw)
            'Update the Player table in the player.mdb database'
            i = dataAdapter.Update(dt)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        'Displays number of rows updated'
        mtxtPlayerID.Text = ""
        mtxtName.Text = ""
        mtxtAge.Text = ""
        mtxtPosition.Text = ""
        mtxtTeam.Text = ""
        mtxtAgent.Text = ""
        mtxtPlayerID.Focus()
        MessageBox.Show("# of rows updated= " & i)


    End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Column 'PlayerID' Does Not Belong To Table.

#2 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3609
  • View blog
  • Posts: 12,417
  • Joined: 12-December 12

Re: Column 'PlayerID' Does Not Belong To Table.

Posted 02 July 2014 - 01:23 PM

This is VB.NET, not VB6. If it were in the wrong forum it would have been moved. There is no need start a duplicate topic.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1