Hi,
I'm wondering if there is a way to send a method parametrs by ref when
DataTabel is a type of this value ?
I done some sort of select over DataTable columns, just by removing them
froma table is each of them isn't on a stirng[], but right no I have to do
it in a wat of:
1. passing DataTable to method (lets call it SelectOverDataTabel)
2. declare a local (in SelectOver...) DataTable, inicialize it with my value
3. doing all things on this local copy (removing.....)
4. and to the parent method send a local copy by return, sth like this
dtMyTable = clsLocalSQL.SelectOverDataTable( dtMyTable,
StringOfSelectedColumns)
Could I do it without closing DataTable in (object) and unpacking it in body
of my static procedure ??
--
best regards
stic 5 9863
Stefan:
I'm not entirely sure I understand the problem but you can definitely pass a
DataTable by reference. However, remember this is a reference type to begin
with and there's a lot to a datatable to keep track of if it's size is very
big so you may see all sorts of performance degradation depending on use.
It's often easier to pass the individual rows of the datatable which are
small and easier to work with.
I'm not sure what you mean by Closing the datatable though, there is no open
or closed state to a DataTable, only the database if that's where its filled
from. If you are referrring to the underlying connection, there's no reason
to leave it open here that I can see.
I'm not sure what the goal is here but if you could explain it a little
more, I could be of more help. Also, if you look at MS's Data Access
Application Block (DAAB) it returns Datasets (so DataTables are essentially
in the same boat) in the executeDataSet method. You can pass these things
over layers, back and forth to web services, you name it you can pass it.
Here's a typical scenario. I have a method that fills a datatable and
returns it:
Declare a datatable and cal lthe method:
DataTable dt = myDataAccessClass.GetDataTable();
//now a method in myDataAccessClass
private DataTable GetDataTable(){
//Open Connection,
DataTable dt = new DataTable();
//Fill datatable
return dt;
}
This is fine to do, is this essentially what you're asking?
"Stefan Turalski (stic)" <st*************@kruk-inkaso.com.pl> wrote in
message news:us*************@TK2MSFTNGP10.phx.gbl... Hi,
I'm wondering if there is a way to send a method parametrs by ref when DataTabel is a type of this value ?
I done some sort of select over DataTable columns, just by removing them froma table is each of them isn't on a stirng[], but right no I have to do it in a wat of: 1. passing DataTable to method (lets call it SelectOverDataTabel) 2. declare a local (in SelectOver...) DataTable, inicialize it with my
value 3. doing all things on this local copy (removing.....) 4. and to the parent method send a local copy by return, sth like this dtMyTable = clsLocalSQL.SelectOverDataTable( dtMyTable, StringOfSelectedColumns)
Could I do it without closing DataTable in (object) and unpacking it in
body of my static procedure ??
-- best regards stic
Hi,
Thanks for you answer but what I need to do is:
1. take one DataTable filled with for example 12 Columns named by letters
A,B,C,...
DataTable dtMyTable = new DataTable();
//sqlconnection code
dataadapert.Fill(dtMyTable) <- when commandtext is "Select A,B,C,D,F,G,...
from sometable
2. take one string[] with allow me to filter this DataTable for examle new
string[] {"A", "C", "H"}
3. pass them to method in static class like this
csLocalSql.SelectOverDataTable(dtMyTable, new string[] {"A", "C", "H"})
4. Then at this method look in loop for every dtMyTable column name, and if
is on this string list I just pass it, if no do
remove("name_with_is_not_at_list_of_string");
5. I return DataTable without columns I don' need.
So as you see I could make local copy of DataTable with I already have afert
fill, and all logic is on local side... And I really don't think that there
is anything unusal - for performence it is even better becouse I done refer
to SQL sever with any select.
Now the question is, how to pass the DataTable to this method as in/out ->
ref, in a way to avoid making local DataTable for with this passed by
reference (by pointer to the structure on stack), and in way to do all this
removes direct on my DataTable..
By closing in (object) I mean boxing and unboxing... I could do it becouse
when I try to do sth like this
csLocalSql.SelecOverDataTabel( ref dtMyTable, new string [] .....);
to method with wait for ref DataTable dtMyTable, string[] str)
compiler shout at me with 'you can't use ref over a this type...
--
best regards
stci
Użytkownik "William Ryan eMVP" <bi**@NoSp4m.devbuzz.com> napisał w
wiadomo¶ci news:eS**************@TK2MSFTNGP10.phx.gbl... Stefan:
I'm not entirely sure I understand the problem but you can definitely pass
a DataTable by reference. However, remember this is a reference type to
begin with and there's a lot to a datatable to keep track of if it's size is
very big so you may see all sorts of performance degradation depending on use. It's often easier to pass the individual rows of the datatable which are small and easier to work with.
I'm not sure what you mean by Closing the datatable though, there is no
open or closed state to a DataTable, only the database if that's where its
filled from. If you are referrring to the underlying connection, there's no
reason to leave it open here that I can see.
I'm not sure what the goal is here but if you could explain it a little more, I could be of more help. Also, if you look at MS's Data Access Application Block (DAAB) it returns Datasets (so DataTables are
essentially in the same boat) in the executeDataSet method. You can pass these things over layers, back and forth to web services, you name it you can pass it.
Here's a typical scenario. I have a method that fills a datatable and returns it:
Declare a datatable and cal lthe method:
DataTable dt = myDataAccessClass.GetDataTable();
//now a method in myDataAccessClass private DataTable GetDataTable(){ //Open Connection, DataTable dt = new DataTable(); //Fill datatable return dt; }
This is fine to do, is this essentially what you're asking? "Stefan Turalski (stic)" <st*************@kruk-inkaso.com.pl> wrote in message news:us*************@TK2MSFTNGP10.phx.gbl... Hi,
I'm wondering if there is a way to send a method parametrs by ref when DataTabel is a type of this value ?
I done some sort of select over DataTable columns, just by removing them froma table is each of them isn't on a stirng[], but right no I have to
do it in a wat of: 1. passing DataTable to method (lets call it SelectOverDataTabel) 2. declare a local (in SelectOver...) DataTable, inicialize it with my value 3. doing all things on this local copy (removing.....) 4. and to the parent method send a local copy by return, sth like this dtMyTable = clsLocalSQL.SelectOverDataTable( dtMyTable, StringOfSelectedColumns)
Could I do it without closing DataTable in (object) and unpacking it in body of my static procedure ??
-- best regards stic
Stefan Turalski (stic) <st*************@kruk-inkaso.com.pl> wrote: Thanks for you answer but what I need to do is: 1. take one DataTable filled with for example 12 Columns named by letters A,B,C,... DataTable dtMyTable = new DataTable(); //sqlconnection code dataadapert.Fill(dtMyTable) <- when commandtext is "Select A,B,C,D,F,G,... from sometable 2. take one string[] with allow me to filter this DataTable for examle new string[] {"A", "C", "H"} 3. pass them to method in static class like this csLocalSql.SelectOverDataTable(dtMyTable, new string[] {"A", "C", "H"}) 4. Then at this method look in loop for every dtMyTable column name, and if is on this string list I just pass it, if no do remove("name_with_is_not_at_list_of_string"); 5. I return DataTable without columns I don' need.
So as you see I could make local copy of DataTable with I already have afert fill, and all logic is on local side... And I really don't think that there is anything unusal - for performence it is even better becouse I done refer to SQL sever with any select.
I think you're missing the difference between reference types and value
types. I certainly don't think you need to pass the DataTable by
reference in this case - passing the reference by value (the default)
is fine, I believe.
See http://www.pobox.com/~skeet/csharp/parameters.html
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Uzytkownik "Jon Skeet [C# MVP]" <sk***@pobox.com> napisal w wiadomosci
news:MP************************@msnews.microsoft.c om... Stefan Turalski (stic) <st*************@kruk-inkaso.com.pl> wrote: Thanks for you answer but what I need to do is: 1. take one DataTable filled with for example 12 Columns named by
letters A,B,C,... DataTable dtMyTable = new DataTable(); //sqlconnection code dataadapert.Fill(dtMyTable) <- when commandtext is "Select
A,B,C,D,F,G,... from sometable 2. take one string[] with allow me to filter this DataTable for examle
new string[] {"A", "C", "H"} 3. pass them to method in static class like this csLocalSql.SelectOverDataTable(dtMyTable, new string[] {"A", "C", "H"}) 4. Then at this method look in loop for every dtMyTable column name,
and if is on this string list I just pass it, if no do remove("name_with_is_not_at_list_of_string"); 5. I return DataTable without columns I don' need.
So as you see I could make local copy of DataTable with I already have
afert fill, and all logic is on local side... And I really don't think that
there is anything unusal - for performence it is even better becouse I done
refer to SQL sever with any select.
I think you're missing the difference between reference types and value types. I certainly don't think you need to pass the DataTable by reference in this case - passing the reference by value (the default) is fine, I believe.
See http://www.pobox.com/~skeet/csharp/parameters.html
Hi,
Could be ;-)
Ok, so as far I as understood if I use ref before parametr, in method
inicialization / calls these DataTable should be send by value (as I
thought) and all opperation could be done right on this table, or I'm
lossing something and there will be no change when I use it ?
The thing btw. is that you couldn't send DataTable as a ref parametr... -
and that is why I started this topic...
--
best regards
stic
Stefan Turalski (stic) <st*************@kruk-inkaso.com.pl> wrote: Could be ;-)
Ok, so as far I as understood if I use ref before parametr, in method inicialization / calls these DataTable should be send by value (as I thought) and all opperation could be done right on this table, or I'm lossing something and there will be no change when I use it ?
The reference is passed by value, but it doesn't create a new copy of
the object itself.
See my article for more information.
The thing btw. is that you couldn't send DataTable as a ref parametr... - and that is why I started this topic...
You *can* pass a DataTable by reference - but you need to state that on
both the method declaration and the method call itself.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: nandan |
last post by:
Hi,
Has any one ever compared the performance of calling a DataTable's
Select method with a stored procedure doing the same thing?
My point is:
dataRows = DataTable.Select(filter) is better or...
|
by: Chuck Ritzke |
last post by:
I keep asking myself this question as I write class modules. What's the
best/smartest/most efficient way to send a large object back and forth to a
class module?
For example, say I have a data...
|
by: CHIN |
last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i
cant find the solution !! )
I have to upload a file to an external site, so, i made a .vbs file , that
logins to...
|
by: Fredrik Rodin |
last post by:
All,
I've been looking around for a solution to my problem for a couple of days
now.
In short, here's my situation:
1.
I'm getting a result from a component back as a datatable and I have...
|
by: Roy |
last post by:
Hi all,
I do have a datatable that looks like:
id Number Description
1 1 Desc1
2 1 Desc2
3 2 Desc3
I need this datatable looks like (with 4 rows...
|
by: D. Shane Fowlkes |
last post by:
I have a function that is called in page_load and the purpose of this
function is to look up basic data in a MSSQL table and return it in the form
of a datatable. The page_load will read the data...
|
by: Joseph Geretz |
last post by:
I'm a bit puzzled by the current recommendation not to send Datasets or
Datatables between application tiers.
http://support.microsoft.com/kb/306134
...
|
by: jehugaleahsa |
last post by:
Hello:
What is the point of using a DataTable in ASP .NET? We are unsure how
you can use them without 1) rebuilding them every postback, or 2)
taking up precious memory. We are not sure how to...
|
by: =?Utf-8?B?anAybXNmdA==?= |
last post by:
I've got a routine that builds a table using different queries, different SQL
Tables, and adding custom fields.
It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the
table...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
|
by: SueHopson |
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
| | |