Imports System.Data.OleDb
Public Class Test
Private p_empid As Integer
Private P_job As String
Property empid() As Integer
Get
Return p_empid
End Get
Set(ByVal Value As Integer)
p_empid = Value
End Set
End Property
Property job() As String
Get
Return P_job
End Get
Set(ByVal Value As String)
P_job = Value
End Set
End Property
End Class
Public Class Testdb
Public Function dbcon() As Test
Dim conn As New OleDbConnection()
Dim cmd As OleDbCommand
conn.ConnectionString = "Provider=OraOLEDB.Oracle;User D=scott;Password=tiger;Data Source=aca013"
cmd = conn.CreateCommand
cmd.CommandText = CommandType.Text
cmd.CommandText = "select * from emp"
cmd.Connection = conn
conn.Open()
Dim reader As OleDbDataReader
reader = cmd.ExecuteReader
Dim arrlist As New ArrayList()
Dim testproperty As Test
While reader.Read
testproperty = New Test()
testproperty.empid = Decimal.ToInt32(reader.GetDecimal(0))
testproperty.job = reader.GetString(1)
arrlist.Add(testproperty)
End While
Return (Test())arrlist.ToArray(typeof(Test))
End Function
End Class
上面的代码想实现从表emp中取出两个字段值,
dbcon() 我想返回数组类型,其元素是Test,请问 Public Function dbcon() As Test 和 Return 这里怎么写啊?
Public Function dbcon() As Test()
在dbcon()函数中定义一个Test()并创建或引用Test的实例,之后 Return 你定义的变量即可
比如:
dim a(5) as test
a(0)=new test
a(0).。。。=。。。
......
return a
即可
Public Function dbcon() As Test()
在dbcon()函数中定义一个Test()并创建或引用Test的实例,之后 Return 你定义的变量即可
比如:
dim a(5) as test
a(0)=new test
a(0).。。。=。。。
......
return a