首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

使用vb.net,用Ado.net,怎么查找Access中一个表是否存在

2011-12-28 
使用vb.net,用Ado.net,如何查找Access中一个表是否存在如何确定Access数据库中的一个表是否存在,使用vb.ne

使用vb.net,用Ado.net,如何查找Access中一个表是否存在
如何确定Access数据库中的一个表是否存在,使用vb.net和ADO.NET,能不能来段代码。谢谢

[解决办法]
rem x=0 表示不存在,x=1 表示存在

strConn= "DBQ= "+server.mappath( "zw.mdb ")+ ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)}; "
set objConn=server.createobject( "Adodb.connection ")
objConn.open strConn
set rsSchema=objConn.openSchema(20)
rsSchema.movefirst

tablename= "gd111 "
x=0
Do Until rsSchema.EOF
if rsSchema( "TABLE_TYPE ")= "TABLE " then

if rsSchema( "TABLE_NAME ")=tablename then
x=1
exit do
end if
end if


rsSchema.movenext
Loop

if x=0 then response.write "没有找到!!! "

if x=1 then response.write "找到了 "


set objConn=nothing
%>


[解决办法]
sql server:

SqlConnection con = new SqlConnection( "server=.;database=demo;user id=sa;pwd=123456 ");
con.Open();
SqlCommand com = new SqlCommand( "select count(*) from systemobject where name= 'table1 ' ", con);
int i = int.Parse(com.ExecuteScalar().ToString());
[解决办法]
dim olecnn as new oleconnection
dim adapter as oledataadapter
dim ds as new dataset

if olecnn.state=state.close then
olecnn.connectionstring= "provider=microsoft.jet.oledb.4.0;data source=path;use id=admin;password= "
olecnn.open
endif

adapter=new oledataadapter( "SELECT *
FROM MSysObjects where name= 'table1 ' and type=1 and flags=0
",olecnn)

adapter.fill(ds)

if ds.tables(O).Count> 0 then
msgbox ( "exists this table ")
else
msgbox ( "not exists this table ")
endif

热点排行