Click here to Skip to main content
Rate this: bad
good
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.
 
Code:
 
'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
                   cnn.Open()
               End If
 
               'delete data
               Dim cmd As New OleDb.OleDbCommand
               cmd.Connection = cnn
               cmd.CommandText = "DELETE FROM NTIdb WHERE pID=" & intStdID
               cmd.ExecuteNonQuery()
               'refresh data
               Me.RefreshData()
 
               'close connection
               cnn.Close()
           End If
       End If
Posted 19-Mar-13 18:17pm
Semeki259
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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"
  Permalink  
Rate this: bad
good
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.
  Permalink  
Comments
Shraa1 at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 20 Mar 2013
Copyright © CodeProject, 1999-2014
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