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
Page 1 of 1
1 Replies - 1141 Views - Last Post: 02 July 2014 - 01:23 PM
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/
Replies To: Column 'PlayerID' Does Not Belong To Table.
Page 1 of 1