Datasets across procedures

softwarevj

Member
Joined
Feb 14, 2006
Messages
15
Location
India
Programming Experience
1-3
Hi friends,

I have a very simple problem. Since being new to VB.NET, i have got fixed up in datasets. I want to know if I can do the following.

dim z as new dataset() //declared in the construstor
Private sub x()

da.Fill(z,"Tablename")
end sub

Private sub y()
dim x as string=ds.tables("Tablename").Rows(0).Item(0)
end sub

what I wanted to know was if i can use a dataset defined, and not declared, in one procedure, in another procedure.

I want to use the same table within the dataset in more than one procedure.

Can i do it.
If yes, how
Please help
 
If you delcare your dataset as class level object i.e

Just below the 'Windows Forms deisgner Generated' bit

VB.NET:
Private Ds as new system.data.dataset

Ds can now be referenced throughout your class. In addition any datatables you add to it can be referenced either by name or index

VB.NET:
Dim Dt as datatable = Ds.Tables(0)
or

VB.NET:
Dim Dt as datatable = Ds.Tables("Name")
 
Hi frnd,
i think you have not understood my question.
I want to populate a dataset with a table in one procedure.
can i reference the same datatable of the same dataset in another procedure

i tried to do so, it is giving me a reference error

how to do this

Thanks
 
In another procedure inside the same class or outside that class?
If it is inside that class then what i have shown you will work. If it is outside the class you can pass it as an argument in a function or sub or create an object of your original class inside the class you want to reference it in, so long as the dataset is declared friend, or public or shared.
 
Datasets

Friend , look wat i have done

private sub form_load(....)

projCmd = New SqlCommand("select * from products", conobj.connection("open"))
projDa = New SqlDataAdapter(projCmd)
projDa.Fill(projDs, "Project")

end sub

private sub button_click( .... )

* msgbox (projds.tables("Project").rows(0).item(0)
** msgbox (projds.tables("Project")

end sub
* the above line gives me an error. how can i access this
** gives no error, but how to access the rows and cols of the datatable

everything is in the same class
 
Datasets

Hi frnd,

Yes I am getting the same error
i am declaring the dataset within the class and not within any procedure
this is wat i am doing

Public Class ControlPanel
......
projDs As New DataSet
..........
form_load(... )
projCmd = New SqlCommand(projStr, con)
projDa = New SqlDataAdapter(projCmd)
projDa.Fill(projDs, "Project")
end sub


public sub desp(...)

msgbox projds.tables("Project").rows(0).items(0)

' this line gives me the error
'is there anything wrong in the code
'please suggest

end sub



end class


thanks for showing your interest in the topic
 
Back
Top