Click here to Skip to main content
11,929,650 members (57,438 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
The error goes like this:

Column named pID cannot be found
Parameter name: columnName

It lets me delete for the first time. Then the error pops out after the 1st attempt.


'check for the selected item in list
       If Form7.DataGridView1.Rows.Count > 0 Then
           If Form7.DataGridView1.SelectedRows.Count > 0 Then
               Dim intStdID As Integer = Form7.DataGridView1.SelectedRows(0).Cells("pID").Value
               'open connection
               If Not cnn.State = ConnectionState.Open Then
               End If
               'delete data
               Dim cmd As New OleDb.OleDbCommand
               cmd.Connection = cnn
               cmd.CommandText = "DELETE FROM NTIdb WHERE pID=" & intStdID
               'refresh data
               'close connection
           End If
       End If
Posted 19-Mar-13 18:17pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

I rather guess that something goes wrong in Me.RefreshData().
So could you add some debugging code in the function you showed us: Check the number of Cells in SelectedRows(0), and find out all their names. That might point to what went wrong.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

you might have deleted the last record and there might be no more data either in the datagrid or the database
or instead of me.refreshdata try datagridview1.refresh
or try passing the index instead of "pID"
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You have already deleted the record at Form7.DataGridView1.SelectedRows(0).Cells("pID").Value.
It cannot be found a second time.
Shraa1 20-Mar-13 7:52am
but even if the record is deleted it wont give an error a second time... the question clearly states an error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100