473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Efficient stack usage

Dear NG,

I am making progress processing trees. I can "span" a tree if I make wise
use of the C# stack methods, push() and pop(). What I want to place on the
stack are rows from a data table. The columns (about a dozen) have string,
decimal, and int data in them. The following code concatinates (tab
delimited) a row and places it on the stack sucessfully. Is there any way to
do this without packing and unpacking the columns into and out of a string?
In other words, place the whole row on the stack? Thanks, Bob

private void button1_Click(object sender, System.EventArgs e)
{
SqlConnection mcs3Connection = MCS3_DB.GetConnection();
string selectStmt = "SELECT * FROM ProdStrt WHERE ps_parent = '500-000'
ORDER BY ps_parent";
SqlCommand selectCmd = new SqlCommand(selectStmt, mcs3Connection);
SqlDataAdapter dataAdapter = new SqlDataAdapter(selectCmd);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "PS"); //dataSet has 1 DataTable IM
// Moving through a table:
int nRows = dataSet.Tables["PS"].Rows.Count;
string strRows = nRows.ToString();
Stack myStack = new Stack();
string strTemp;
MessageBox.Show("Number of rows: " + strRows);
for (int i = 0; i < nRows; i++)
{
strTemp = dataSet.Tables["PS"].Rows[i]["ps_component"].ToString() + "\t" +
dataSet.Tables["PS"].Rows[i]["ps_parent"].ToString();
myStack.Push(strTemp);
MessageBox.Show("entry: " + strTemp, "Info");
}
for (int i = 0; i < nRows; i++)
{
strTemp = (string) myStack.Pop();
MessageBox.Show("exit: " + strTemp, "Info");
}

}
Nov 16 '05 #1
3 1686
Hi,

I really do not understand what you are trying to do, what a tree has to do
with a datatable or a stack?

if you want to store a "row" in a stack, why dont you get it as a single
field from the DB and just store this value in the stack?

beware that the char you use as column delimiter may appear inside a string
column.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Robert Schuldenfrei" <Ro****************@discussions.microsoft.com> wrote
in message news:60**********************************@microsof t.com...
Dear NG,

I am making progress processing trees. I can "span" a tree if I make wise
use of the C# stack methods, push() and pop(). What I want to place on
the
stack are rows from a data table. The columns (about a dozen) have
string,
decimal, and int data in them. The following code concatinates (tab
delimited) a row and places it on the stack sucessfully. Is there any way
to
do this without packing and unpacking the columns into and out of a
string?
In other words, place the whole row on the stack? Thanks, Bob

private void button1_Click(object sender, System.EventArgs e)
{
SqlConnection mcs3Connection = MCS3_DB.GetConnection();
string selectStmt = "SELECT * FROM ProdStrt WHERE ps_parent = '500-000'
ORDER BY ps_parent";
SqlCommand selectCmd = new SqlCommand(selectStmt, mcs3Connection);
SqlDataAdapter dataAdapter = new SqlDataAdapter(selectCmd);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "PS"); //dataSet has 1 DataTable IM
// Moving through a table:
int nRows = dataSet.Tables["PS"].Rows.Count;
string strRows = nRows.ToString();
Stack myStack = new Stack();
string strTemp;
MessageBox.Show("Number of rows: " + strRows);
for (int i = 0; i < nRows; i++)
{
strTemp = dataSet.Tables["PS"].Rows[i]["ps_component"].ToString() + "\t" +
dataSet.Tables["PS"].Rows[i]["ps_parent"].ToString();
myStack.Push(strTemp);
MessageBox.Show("entry: " + strTemp, "Info");
}
for (int i = 0; i < nRows; i++)
{
strTemp = (string) myStack.Pop();
MessageBox.Show("exit: " + strTemp, "Info");
}

}

Nov 16 '05 #2
Robert,

There is no reason why you shouldn't be able to store the DataRow itself
to the stack.

However, what I don't understand is why you don't just use the DataTable
class, and add a new row. Add a column which is a number, and when you add,
populate it with the number of rows currently in the table. Then, when you
pop off the stack, just remove the row at count - 1.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Robert Schuldenfrei" <Ro****************@discussions.microsoft.com> wrote
in message news:60**********************************@microsof t.com...
Dear NG,

I am making progress processing trees. I can "span" a tree if I make wise
use of the C# stack methods, push() and pop(). What I want to place on
the
stack are rows from a data table. The columns (about a dozen) have
string,
decimal, and int data in them. The following code concatinates (tab
delimited) a row and places it on the stack sucessfully. Is there any way
to
do this without packing and unpacking the columns into and out of a
string?
In other words, place the whole row on the stack? Thanks, Bob

private void button1_Click(object sender, System.EventArgs e)
{
SqlConnection mcs3Connection = MCS3_DB.GetConnection();
string selectStmt = "SELECT * FROM ProdStrt WHERE ps_parent = '500-000'
ORDER BY ps_parent";
SqlCommand selectCmd = new SqlCommand(selectStmt, mcs3Connection);
SqlDataAdapter dataAdapter = new SqlDataAdapter(selectCmd);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "PS"); //dataSet has 1 DataTable IM
// Moving through a table:
int nRows = dataSet.Tables["PS"].Rows.Count;
string strRows = nRows.ToString();
Stack myStack = new Stack();
string strTemp;
MessageBox.Show("Number of rows: " + strRows);
for (int i = 0; i < nRows; i++)
{
strTemp = dataSet.Tables["PS"].Rows[i]["ps_component"].ToString() + "\t" +
dataSet.Tables["PS"].Rows[i]["ps_parent"].ToString();
myStack.Push(strTemp);
MessageBox.Show("entry: " + strTemp, "Info");
}
for (int i = 0; i < nRows; i++)
{
strTemp = (string) myStack.Pop();
MessageBox.Show("exit: " + strTemp, "Info");
}

}

Nov 16 '05 #3
Hi Nick,

Thank you for the reply. I tried to push(dataSet.Tables["PS"].Rows[i]) on
to the stack, but I recieved an error. Forgot what it was, but if you think
that is the right thing, I will try again. I am not sure what you are
suggesting with your idea to: "just use the DataTable class, and add a new
row. Add a column which is a number, and when you add, populate it with the
number of rows currently in the table."

I need to push and pop certain rows on and off the stack to "span" the tree.
My example does not show the tree processing yet. While I am waiting your
suggestion, I am developing the added processing using the string approach.
Later on I can go for the more efficient method. Thanks for your help. Bob

"Nicholas Paldino [.NET/C# MVP]" wrote:
Robert,

There is no reason why you shouldn't be able to store the DataRow itself
to the stack.

However, what I don't understand is why you don't just use the DataTable
class, and add a new row. Add a column which is a number, and when you add,
populate it with the number of rows currently in the table. Then, when you
pop off the stack, just remove the row at count - 1.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Robert Schuldenfrei" <Ro****************@discussions.microsoft.com> wrote
in message news:60**********************************@microsof t.com...
Dear NG,

I am making progress processing trees. I can "span" a tree if I make wise
use of the C# stack methods, push() and pop(). What I want to place on
the
stack are rows from a data table. The columns (about a dozen) have
string,
decimal, and int data in them. The following code concatinates (tab
delimited) a row and places it on the stack sucessfully. Is there any way
to
do this without packing and unpacking the columns into and out of a
string?
In other words, place the whole row on the stack? Thanks, Bob

private void button1_Click(object sender, System.EventArgs e)
{
SqlConnection mcs3Connection = MCS3_DB.GetConnection();
string selectStmt = "SELECT * FROM ProdStrt WHERE ps_parent = '500-000'
ORDER BY ps_parent";
SqlCommand selectCmd = new SqlCommand(selectStmt, mcs3Connection);
SqlDataAdapter dataAdapter = new SqlDataAdapter(selectCmd);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "PS"); //dataSet has 1 DataTable IM
// Moving through a table:
int nRows = dataSet.Tables["PS"].Rows.Count;
string strRows = nRows.ToString();
Stack myStack = new Stack();
string strTemp;
MessageBox.Show("Number of rows: " + strRows);
for (int i = 0; i < nRows; i++)
{
strTemp = dataSet.Tables["PS"].Rows[i]["ps_component"].ToString() + "\t" +
dataSet.Tables["PS"].Rows[i]["ps_parent"].ToString();
myStack.Push(strTemp);
MessageBox.Show("entry: " + strTemp, "Info");
}
for (int i = 0; i < nRows; i++)
{
strTemp = (string) myStack.Pop();
MessageBox.Show("exit: " + strTemp, "Info");
}

}


Nov 16 '05 #4

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

Similar topics

3
by: Chris Tanger | last post by:
I am creating a class that has a method "Write" that I wish to make threadsafe. The method must block calling threads until the task performed in write is complete. Only 1 thread at a time can...
48
by: Michael Sig Birkmose | last post by:
Hi everyone! Does anyone know, if it is possible to meassure the maximum stack usage of a C program throughout it's entire execution? -- Michael Birkmose
6
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
1
by: | last post by:
I was viewing some strange behaviour in c# so I tried a comparison in vb.net A simple 1 line console application written in both c# and vb.net (One line meaning one line in the main function). ...
9
by: Ajay | last post by:
Hi all, Can I know what is the stack space and heap space allocated by the compiler.Can i increase it or decrease it.if yes,pleae tell me theway to do it.Thanks in advance. Cheers, Ajay
5
by: sunny | last post by:
Hi All Is there any way to determine stack and heap size, during runtime. i.e can we predict stack overflow. etc
11
by: Nehil | last post by:
I would like to know which is dynamic in nature. if i refer the C memory model (Richard Steven), it is shown that both stack and heap grow towards each other. Now, can one go into other's area and...
30
by: asit | last post by:
We kno that data can be pushed onto the stack or popped 4m it. Can stack be traversed ??
87
by: CJ | last post by:
Hello: We know that C programs are often vulnerable to buffer overflows which overwrite the stack. But my question is: Why does C insist on storing local variables on the stack in the first...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...

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.