各位好:
最近做一个考勤管理的项目,要求用oracle作后台数据库。而连接数据库不用.net自带控件的
我找了oracle网站的model照着写了一段代码,可老是不行。请高手帮我分析一下原因:
代码如下:
Dim oradb As String = "Data Source=(DESCRIPTION=" _
+ "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.22)(PORT=1521)))" _
+ "(CONNECT_DATA=(SERVER=192.168.1.22)(SERVICE_NAME=EPSON)));" _
+ "User Id=EPSON;Password=EPSON;" '连接数据库
Dim conn As New OracleConnection(oradb)
Try
conn.Open()
Dim cmd As New OracleCommand
cmd.Connection = conn
Dim sql As String = "select NAME from YUANGONGJIBEN where ID = 001001" ' VB.NET
cmd.CommandText = "select ID, NAME from YUANGONGJIBEN"
Dim cmd1 As New OracleCommand(sql, conn)
cmd1.CommandType = CommandType.Text
'连接检查
Dim dr As OracleDataReader = cmd.ExecuteReader() ' VB.NET
dr.Read()
Label1.Text = dr.Item("dname") ' retrieve by column name
Label1.Text = dr.Item(0) ' retrieve the first column in the select list
Label1.Text = dr.GetString(0) ' retrieve the first column in the select list
Label1.Text = CStr(dr.Item("ID")) ' VB.NET integer to string cast
Catch ex As OracleException ' catches only Oracle errors
Select Case ex.Number
Case 1
' MessageBox.Show("Error attempting to insert duplicate data.")
Case 12545
MsgBox("The database is unavailable.")
Case Else
MsgBox("Database error: " + ex.Message.ToString())
End Select
Catch ex As Exception ' catches any error
'MsgBox(ex.Message.ToString(), , )
Finally
conn.Close() ' VB.NET
conn.Dispose() ' VB.NET
End Try
本人由于才学.net不到一个月的时间,所以可能会问一些很不成问题的问题,
还请见谅!
等待........................