Click here to Skip to main content
16,020,628 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
Hi;I am trying to execute this code
//////////////////////////////////////////////////////////////////////
C#
string sSql = "delete from Vacation where EmployeeID = ?";
           using (OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Feras\Documents\Visual Studio 2008\Projects\Manshiah\Manshiah\MansheyaDB_be.mdb"))
           {
               connection.Open();
               OleDbCommand command = new OleDbCommand(sSql, connection);
               command.Parameters.AddWithValue("?", Convert.ToInt32(txtEmployeeId.Text));
               OleDbDataReader myReader = command.ExecuteReader();
               try
               {
                   while (myReader.Read())
                   {
                       Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1));
                   }
               }
               finally
               {
                   // always call Close when done reading.
                   myReader.Close();
                   connection.Close();
               }
///////////////////////////////////////////////////////
but it results this Exception: Deleted row information cannot be accessed through the row
Posted
Updated 3-Aug-12 3:46am
v2

1 solution

Instead of
C#
OleDbDataReader myReader = command.ExecuteReader();

I think you want to use
int numDeleted = command.ExecuteNonQuery();

And then obviously remove the myReader.Read() loop.

Here's a link for more information:
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.executenonquery.aspx[^]
 
Share this answer
 
Comments
feras.abulhaija 3-Aug-12 10:40am    
thanks a lot it is done and worked correctly

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900