class Conn_DB:
public class Conn_DB
{
int i=0;
public static string str="";
public static string ErrorStr="";
public OleDbConnection Conn=null;
public Conn_DB()
{
try
{
   Conn=new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+str+";");
Conn.Open();
}
catch(OleDbException ex)
{
     Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message);
      return ;
}
}
           public int Insert(string SqlSyntax)
{
i = 0;
try
{
OleDbCommand cmd = new OleDbCommand(SqlSyntax,this.Conn);
i = cmd.ExecuteNonQuery();                    return i ;
}
catch(OleDbException ex)
{
                        return i ;
}
finally
{
Conn.Close();
}
}
}*.aspx
private void Page_Load(object sender, System.EventArgs e)
{
Conn_DB.str=Server.MapPath("abc.mdb");
conn=new Conn_DB();
TextBox1.Text=conn.Delete("delete from [user] where uid='aaa'").ToString();
}TextBox1的值為0說明刪除不成功,為1就成功.
為什麼會刪除不了.Sql語句是對的...........................
急急急急急急急急急急急急急急急急急急急急急急急急急急急

解决方案 »

  1.   

    有呀delete,update,insert方法的寫法是一樣的
      

  2.   

    delete的SQL语句看下,函数没有问题
    再说你的try catch隐藏了错误的原因,建议在catch里使用MessageBox.Show(ex.Message)看下你的错误类型
      

  3.   

    各位老大,這是asp.net的,不是winform的,那有messagebox
      

  4.   

    不是这个原因,是你aspnet这个用户权限的问题,这是系统默认运行asp.net的用户,那么这个用户对你的文件所存放目录只有读的权限,并没有写的权限,添加这个权限即可。