I need to work with object whose values are taken from database. I do the database scan in Function scan and it seems to run well. But i still have the problem, how to get values (result of function scan) out of the function?
Here is my code. I'm a beginner in VB .Net. So, if there's any mistake in my basic knowledge, please let me know it.
Public Class data
Dim _field1 As Integer
Dim _field2 As Integer
Dim _field3 As Integer
Dim _field4 As Integer
Dim _field5 As Integer
Public Property field1() As Integer
Get
Return _field1
End Get
Set(ByVal value As Integer)
_field1 = value
End Set
End Property
Public Property field2() As Integer
Get
Return _field2
End Get
Set(ByVal value As Integer)
_field2 = value
End Set
End Property
Public Property field3() As Integer
Get
Return _field3
End Get
Set(ByVal value As Integer)
_field3 = value
End Set
End Property
Public Property field4() As Integer
Get
Return _field4
End Get
Set(ByVal value As Integer)
_field4 = value
End Set
End Property
Public Property field5() As Integer
Get
Return _field5
End Get
Set(ByVal value As Integer)
_field5 = value
End Set
End Property
End Class
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
scan()
'HERE IS THE PROBLEM. HOW TO GET VALUE FROM arr?'
End Sub
Public Function scan() As Object
Dim ds As New DataSet
Dim connetionString As String
Dim oledbCnn As OleDbConnection
Dim oledbAdapter_1 As OleDbDataAdapter
Dim sql_list As String
connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=datasource.mdb;"
sql_list = "SELECT * FROM sample"
oledbCnn = New OleDbConnection(connetionString)
oledbCnn.Open()
oledbAdapter_1 = New OleDbDataAdapter(sql_list, oledbCnn)
oledbAdapter_1.Fill(ds)
Dim arr(ds.Tables(0).Rows.Count - 1) As data
For i = 0 To (ds.Tables(0).Rows.Count - 1)
Dim temp As data = New data
temp.field1 = ds.Tables(0).Rows(i).Item(0)
temp.field2 = ds.Tables(0).Rows(i).Item(1)
temp.field3 = ds.Tables(0).Rows(i).Item(2)
temp.field4 = ds.Tables(0).Rows(i).Item(3)
temp.field5 = ds.Tables(0).Rows(i).Item(4)
arr(i) = temp
Next
Return arr
End Function
End Class
Ashutosh Pathak
Blog: http://catchcode.blogspot.com Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
dee_nu
Member
3 Points
11 Posts
How to get object value from function?
Apr 04, 2012 01:30 AM|LINK
Please help me to solve this problem.
I need to work with object whose values are taken from database. I do the database scan in Function scan and it seems to run well. But i still have the problem, how to get values (result of function scan) out of the function?
Here is my code. I'm a beginner in VB .Net. So, if there's any mistake in my basic knowledge, please let me know it.
Public Class data Dim _field1 As Integer Dim _field2 As Integer Dim _field3 As Integer Dim _field4 As Integer Dim _field5 As Integer Public Property field1() As Integer Get Return _field1 End Get Set(ByVal value As Integer) _field1 = value End Set End Property Public Property field2() As Integer Get Return _field2 End Get Set(ByVal value As Integer) _field2 = value End Set End Property Public Property field3() As Integer Get Return _field3 End Get Set(ByVal value As Integer) _field3 = value End Set End Property Public Property field4() As Integer Get Return _field4 End Get Set(ByVal value As Integer) _field4 = value End Set End Property Public Property field5() As Integer Get Return _field5 End Get Set(ByVal value As Integer) _field5 = value End Set End Property End ClassPublic Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load scan() 'HERE IS THE PROBLEM. HOW TO GET VALUE FROM arr?' End Sub Public Function scan() As Object Dim ds As New DataSet Dim connetionString As String Dim oledbCnn As OleDbConnection Dim oledbAdapter_1 As OleDbDataAdapter Dim sql_list As String connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=datasource.mdb;" sql_list = "SELECT * FROM sample" oledbCnn = New OleDbConnection(connetionString) oledbCnn.Open() oledbAdapter_1 = New OleDbDataAdapter(sql_list, oledbCnn) oledbAdapter_1.Fill(ds) Dim arr(ds.Tables(0).Rows.Count - 1) As data For i = 0 To (ds.Tables(0).Rows.Count - 1) Dim temp As data = New data temp.field1 = ds.Tables(0).Rows(i).Item(0) temp.field2 = ds.Tables(0).Rows(i).Item(1) temp.field3 = ds.Tables(0).Rows(i).Item(2) temp.field4 = ds.Tables(0).Rows(i).Item(3) temp.field5 = ds.Tables(0).Rows(i).Item(4) arr(i) = temp Next Return arr End Function End ClassAshutosh Pat...
Contributor
5737 Points
1105 Posts
Re: How to get object value from function?
Apr 04, 2012 03:49 AM|LINK
write down:
Dim ob as Object= scan()
Blog: http://catchcode.blogspot.com
Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
dee_nu
Member
3 Points
11 Posts
Re: How to get object value from function?
Apr 04, 2012 03:54 AM|LINK
I've solved this :D
I just need to fix the function declaration