c#连ACESS时怎么判断某个表是否存在啊? c#连ACESS时怎么判断某个表是否存在啊?还有能不能直接读出来这个表当中有什么内容? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select 1 from msysobject where name = 'tablename';后面的应该知道了吧 1. 取得表列表: private string[] gettableNameList(OleDbConnection oleDbConnection) { DataTable schemaTable = oleDbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] {null, null, null, "TABLE"}); int rowCount = schemaTable.DefaultView.Count; string[] tableNameList = new string[rowCount]; for(int i = 0; i<rowCount; i++) { tableNameList[i] = schemaTable.DefaultView.Table.Rows[i]["TABLE_NAME"].ToString(); } return tableNameList; }2. 判断表是否存在: private bool tableNameIsExist(string TbName, string[] TbNameList) { bool tbIsExist = false; foreach(string tbName in TbNameList) { if (tbName == TbName) tbIsExist = true; } return tbIsExist; } 请帮我看看这么写错误出在哪string dbCommand = null;OleDbDataReader myDataReader = null;string userName = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\\06.mdb;";this.DBConnect(userName);//连接名为06.mdb的数据库dbCommand = "SELECT * FROM tbl1 WHERE Flags=0 AND Type=1 AND name = 'tbl1';";DBSelect(dbCommand, ref myDataReader);//读取try{ while(myDataReader.HasRows) { string str2 = myDataReader[0].ToString(); }}catch (Exception ex){}try{ dbCommand = "SELECT * FROM tbl1 WHERE Flags=0 AND Type=1;"; DBSelect(dbCommand, ref myDataReader);//读取 while (myDataReader.HasRows) { string str2 = myDataReader[0].ToString(); }}catch (Exception ex1){}this.DBDisconnect();//关闭连接06.mdb 在当前窗体怎么关掉另一个窗体? jquery里的jconfirm和webdialog的相关问题 C# winfrom 图片复制粘贴 C#打包应用程序,能否让在没有装.net上运行 关于datarow 事件操作 vs.net中有自带的加密控件吗?还是要另外去找? webbrowser中显示带有VML元素的网页问题 微软的VS C#觉得太庞大请推荐几个精干的C#编辑器来试试 新手求助,我要怎样得到这个model的长度,以此来循环 如何批量操作 DataTable中某一列的值 正则表达式的用法 老问题,学习c#怎么进阶
后面的应该知道了吧
private string[] gettableNameList(OleDbConnection oleDbConnection)
{
DataTable schemaTable = oleDbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,
new object[] {null, null, null, "TABLE"});
int rowCount = schemaTable.DefaultView.Count;
string[] tableNameList = new string[rowCount];
for(int i = 0; i<rowCount; i++)
{
tableNameList[i] = schemaTable.DefaultView.Table.Rows[i]["TABLE_NAME"].ToString();
}
return tableNameList; }2. 判断表是否存在:
private bool tableNameIsExist(string TbName, string[] TbNameList)
{
bool tbIsExist = false;
foreach(string tbName in TbNameList)
{
if (tbName == TbName)
tbIsExist = true;
}
return tbIsExist;
}
string dbCommand = null;
OleDbDataReader myDataReader = null;
string userName = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\\06.mdb;";
this.DBConnect(userName);//连接名为06.mdb的数据库dbCommand = "SELECT * FROM tbl1 WHERE Flags=0 AND Type=1 AND name = 'tbl1';";DBSelect(dbCommand, ref myDataReader);//读取
try
{
while(myDataReader.HasRows)
{
string str2 = myDataReader[0].ToString(); }
}
catch (Exception ex)
{
}try
{
dbCommand = "SELECT * FROM tbl1 WHERE Flags=0 AND Type=1;"; DBSelect(dbCommand, ref myDataReader);//读取 while (myDataReader.HasRows)
{
string str2 = myDataReader[0].ToString(); }
}
catch (Exception ex1)
{
}
this.DBDisconnect();//关闭连接06.mdb