比如Delete [Easy] where [Point] < 60
这样简单的东西是不可能错的啦,但是执行失败
请问是不是没法这样操作的,只能用Select语句
class ExcelConnection
{
public string ExcelConnString;
public OleDbConnection ExcelOldDbConn = new OleDbConnection();
public ExcelConnection(string ExcelFileName)
{
ExcelConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ExcelFileName + ";Extended Properties=Excel 8.0";
ExcelOldDbConn.ConnectionString = ExcelConnString;
}
public void ExcelOpen()
{
ExcelOldDbConn.Open();
}
public void ExcelClose()
{
ExcelOldDbConn.Close();
}
public DataSet ExcelReadDS(string Range, string SheetName, string Condition)
{
string ExcelSelectStr = "SELECT " + Range + " FROM " + SheetName + " " + Condition; //查询语句
OleDbDataAdapter ExcelSelectDA = new OleDbDataAdapter(ExcelSelectStr, ExcelOldDbConn); //执行查询
DataSet ExcelDS = new DataSet();
ExcelSelectDA.Fill(ExcelDS); //填充数据
ExcelSelectDA.Dispose();
return ExcelDS;
}
public OleDbDataReader ExcelReadDR(string Range, string SheetName, string Condition)
{
string ExcelSelectStr = "SELECT " + Range + " FROM " + SheetName + " " + Condition;
OleDbCommand ExcelSelectCmd = new OleDbCommand(ExcelSelectStr, ExcelOldDbConn);
OleDbDataReader ExcelDR = ExcelSelectCmd.ExecuteReader();
return ExcelDR;
}
public void ExcelInsert(string SheetName, string Range, string Value, string Condition)
{
string ExcelInsertStr = "INSERT INTO " + SheetName + " ( " + Range + " ) VALUES ( " + Value + " ) " + Condition;
OleDbCommand ExcelInsertCmd = new OleDbCommand(ExcelInsertStr, ExcelOldDbConn);
ExcelInsertCmd.ExecuteNonQuery();
ExcelInsertCmd.Dispose();
}
public void ExcelUpdate(string SheetName, string UpdateValues, string Condition)
{
string ExcelUpdateStr = "UPDATE " + SheetName + " " + UpdateValues + " " + Condition;
OleDbCommand ExcelUpdateCmd = new OleDbCommand(ExcelUpdateStr, ExcelOldDbConn);
ExcelUpdateCmd.ExecuteNonQuery();
ExcelUpdateCmd.Dispose();
}
public void ExcelDelete(string SheetName, string Condition)
{
string ExcelDeleteStr = "Delete " + SheetName + " " + Condition;
OleDbCommand ExcelDeleteCmd = new OleDbCommand(ExcelDeleteStr, ExcelOldDbConn);
ExcelDeleteCmd.ExecuteNonQuery();
ExcelDeleteCmd.Dispose();
}
}
这是一个我写的Excel文件操作类的全部代码,查,添,改,都没问题了,但是删会报错
请指教删的问题
贴在这里,也算开源了~