一聚教程网:一个值得你收藏的教程网站

热门教程

[ASP.NET]对Oracle数据库创建表/判断数据表是否已存在

时间:2022-06-30 10:40:10 编辑:袖梨 来源:一聚教程网

对Oracle数据库创建表:
Dim myConnectionString As String
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim myCreateSQL As String
myConnectionString = "Provider='OraOLEDB.Oracle.1';User ID=[User ID];Data Source=[Data Source];Extended Properties=;Persist Security Info=True;Password=[Password]"
myConnection = New OleDbConnection(myConnectionString)
myCreateSQL = "create table (abc varchar2(10))"
myCommand = New OleDbCommand(myCreateSQL)
myCommand.Connection = myConnection
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
判断数据表是否已存在:
'DataBaseName --表名
Private Function SQLExistDatabase(ByVal DataBaseName As String) As Boolean
Dim orcConnDb As OracleConnection
Dim strSelect As String
Dim odaExistDatabase As OracleDataAdapter
Dim dsExistDatabase As New DataSet
orcConnDb = New OracleConnection
orcConnDb.ConnectionString = "data source=[data source];" _
& "persist security info=False;" _
& "user id=[]user id;Password=[Password];"
orcConnDb.Open()
strSelect = "select count(*) from user_tables where table_name='" & ReplaceEN(DataBaseName) & "'"
odaExistDatabase = New OracleDataAdapter(strSelect, orcConnDb)
odaExistDatabase.Fill(dsExistDatabase)
If dsExistDatabase.Tables(0).Rows(0)(0) = 0 Then
orcConnDb.Close()
Return False
Else
orcConnDb.Close()
Return True
End If
End Function
'小写英字转换成大写英字
'enString -- 字符串
Private Function ReplaceEN(ByVal enString As String) As String
Dim i As Integer
For i = Asc("a") To Asc("z")
enString = enString.Replace(CChar(ChrW(i)), CChar(ChrW(i - 32)))
Next
Return enString
End Function

热门栏目