我正在尝试从C#中的Microsoft Access表中删除多行 [英] I'm trying to delete multiple rows from a Microsoft Access table in C#

查看:302
本文介绍了我正在尝试从C#中的Microsoft Access表中删除多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨;我正在尝试执行此代码
///////////////////////////////////////////////////////////////////////

Hi;I am trying to execute this code
//////////////////////////////////////////////////////////////////////

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

推荐答案

而不是
来访问已删除的行信息
Instead of
OleDbDataReader myReader = command.ExecuteReader();


我想你要用


I think you want to use

int numDeleted = command.ExecuteNonQuery();


然后显然删除myReader.Read()循环.

这是更多信息的链接:
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbcommand.executenonquery.aspx [ ^ ]


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[^]


这篇关于我正在尝试从C#中的Microsoft Access表中删除多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆