473,810 Members | 2,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sending DataTable by ref - is there a way to do it, and any sense of doing it ?

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 SelectOverDataT abel)
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.Sel ectOverDataTabl e( dtMyTable,
StringOfSelecte dColumns)

Could I do it without closing DataTable in (object) and unpacking it in body
of my static procedure ??

--
best regards
stic
Nov 16 '05 #1
5 10096
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 = myDataAccessCla ss.GetDataTable ();

//now a method in myDataAccessCla ss
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******** *****@TK2MSFTNG P10.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 SelectOverDataT abel)
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.Sel ectOverDataTabl e( dtMyTable,
StringOfSelecte dColumns)

Could I do it without closing DataTable in (object) and unpacking it in body of my static procedure ??

--
best regards
stic

Nov 16 '05 #2
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.Fil l(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.Sele ctOverDataTable (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_wi th_is_not_at_li st_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.Sele cOverDataTabel( 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.de vbuzz.com> napisał w
wiadomo¶ci news:eS******** ******@TK2MSFTN GP10.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 = myDataAccessCla ss.GetDataTable ();

//now a method in myDataAccessCla ss
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******** *****@TK2MSFTNG P10.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 SelectOverDataT abel)
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.Sel ectOverDataTabl e( dtMyTable,
StringOfSelecte dColumns)

Could I do it without closing DataTable in (object) and unpacking it in

body
of my static procedure ??

--
best regards
stic


Nov 16 '05 #3
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.Fil l(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.Sele ctOverDataTable (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_wi th_is_not_at_li st_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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

Uzytkownik "Jon Skeet [C# MVP]" <sk***@pobox.co m> napisal w wiadomosci
news:MP******** *************** *@msnews.micros oft.com...
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.Fil l(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.Sele ctOverDataTable (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_wi th_is_not_at_li st_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
Nov 16 '05 #5
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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2139
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 Passing paramters to stored procedure? The datatable holds about 500-700 rows at any given time. If I select one of the approaches the business logic will go into respective layers.With dotnet in picture what would be a good approach
4
2167
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 access module that creates a large disconnected dataset from a database. I want to pass that dataset back to the calling program. And then perhaps I want to send that dataset to another class module. At first it seems that the "object oriented"...
20
2516
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 the site, and then i have to select the file to upload.. i used sendkeys.. and i worked perfect.. BUT ... the computer must be locked for security ( obviusly ) reazons.. so..i think this probable solutions to unlock the computer and run the...
2
3182
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 no option to sort the different columns during the call to the component.
2
2482
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 which the third one is blank): id Number Description 1 1 Desc1 2 1 Desc2
10
3721
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 and then fill a few simple labels. **Assuming** that I wrote the function properly, how exactly can I write the page_load sub to read the data from the function? I've tried a few examples from a couple of books I have but can't seem to get a...
15
13518
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 http://msdn2.microsoft.com/en-us/library/ms996381.aspx Formerly, with classic Microsoft DNA architecture, the ADO Recordset was a primary transport medium, recommended for transmitting data between application tiers. In fact, there are whole books written on the subject.
5
5898
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 store a DataTable in any other way outside of our servers. In doing so, we leave ourselves open to large memory requirements. Furthermore, most web pages do not really support multiple changes per transaction. In other words, when the user submits...
9
6996
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 population. Whenever I call the thread, I pass it a structure containing the table and a few other parameters. The table goes in as a reference, but the other items are passed normally.
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10643
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10391
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10121
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4333
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3862
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.