/// 删除Access指定表
/// </summary>
/// <param name="pPath"></param>
/// <param name="pTableName"></param>
/// <returns></returns>
public static bool DeleteAccessTable(string pPath, string pTableName)
{
bool vCheck = true
try
{
string vConn = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0Data Source='{0}'", pPath)
string vCommSql = string.Format(" drop table [{0}] ", pTableName)
OleDbConnection olconn = new OleDbConnection(vConn)
OleDbCommand olcomm = new OleDbCommand(vCommSql, olconn)
olconn.Open()
olcomm.ExecuteNonQuery()
olconn.Close()
}
catch (Exception vErr)
{
vCheck = false
string vOutInfo = vErr.Message
}
return vCheck
}
这样可以的,注意 表名不可有 单引号。
语法如下:using System.Data.OleDb
using System.Data
//连接指定的Access数据库
String ConnString ="Provider=Microsoft.Jet.OLEDB.4.0Data Source=MyMDB.mdb"
//SQL语句
String SQLString ="select * from TestDB"
System.Data.OleDb.OleDbConnection OleDBConn1 = new System.Data.OleDb.OleDbConnection(ConnString)
//创建一个DataSet对象
DataSet DataSet1 = new DataSet()
//创建一个OleDbDataAdapter对象
System.Data.OleDb.OleDbDataAdapter OleDbDataAdapter1 = new System.Data.OleDb.OleDbDataAdapter(SQLString,OleDBConn1)
//打开连接
OleDBConn1.Open()
//通过OleDbDataAdapter对象填充数据集
OleDbDataAdapter1。Fill(DataSet1,"TT")
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)