Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass datatable to Sub 1

Status
Not open for further replies.

hamking01

Programmer
May 30, 2004
238
US
I'm trying to pass a datatable to a sub to perform some actions. I've got something to this sort:

Function dtFeedbackLoad()
Dim dt As DataTable = New DataTable("Feedback")
Dim dr0, dr1, dr2 As DataRow
Dim Id As DataColumn = New DataColumn("Id")
Dim Recv As DataColumn = New DataColumn("dt_Recvd")
Id.DataType = Type.GetType("System.Int32")
Recv.DataType = Type.GetType("System.String")
dt.Columns.Add(Id)
dt.Columns.Add(Recv)
dr0 = dt.NewRow()
dr0.Item("IdPerson") = 0
dr0.Item("dt_Recvd") = ""
dr0.Item("dt_Sign") = ""
dr0.Item("txt_Notes") = ""
dt.Rows.Add(dr0)
dr1 = dt.NewRow()
dr1.Item("Id") = 1
dr1.Item("dt_Recvd") = txt1.Text
dr1.Item("dt_Sign") = txt2.Text
dr1.Item("txt_Notes") = txt2.Text
dt.Rows.Add(dr1)
Return dt
End Function

Sub CkUpdate(ByVal x As Integer)
Dim cktbl As DataTable = New DataTable(dtFeedbackLoad()) 'this the the datatable above
If (cktbl.Rows(x)(1).ToString() = "") Then
'ERROR OCCURS HERE: Cast from type 'DataTable' to type 'String' is not valid



End Sub

 
Code:
Function dtFeedbackLoad()
You aren't declaring what type that dtFeedbackLoad should return. Add an As keyword, followed by the datatype you want returned.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
You can return an object from your function as you did.
It just works better sometimes if you return actual DataTable.
Function dtFeedbackLoad() as DataTable
Now it as Object when nothing is written.



The problem though is here:
Dim cktbl As DataTable = New DataTable(dtFeedbackLoad()) 'this the the datatable above

Should Be:
Dim cktbl As DataTable = dtFeedbackLoad() 'this the the datatable above

 
Thanx for the response, figured it out just after I posted the thread.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top