How to wait for a completed query

A

Andrew Mueller

Hello,

I have the following code:


DataSet myDataSet = new DataSet();

OleDbDataAdapter adapter = new OleDbDataAdapter(sb.ToString(),myConn);

adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

int count = adapter.Fill(myDataSet,"ihrawdata");

foreach (DataTable table in myDataSet.Tables)
{
foreach (DataRow row in table.Rows)
{
return Convert.ToString(row[0]);
}
}
return "NONE";
}


How do I wait for the query to have completed before attempting to fill the
dataset object? I think I am running into a timing issue of trying to fill
to fast because I am making many successive queries and I would like to test
my theory.

Thanks!

PS - Thread.Sleep does not work because it stops everything apparently. I
do not want to stop the query process, just wait for the completed data from
my table, ihrawdata.

Andrew Mueller
 
G

Greg Ewing [MVP]

Andrew, due to the way that the OLEDataAdapter.Fill() works you don't need
to worry that you are accessing the data too quickly. Once Fill returns all
of the data is available. What exactly are you seeing that leads you to
your conclusion?
 
C

Chris R. Timmons

Hello,

I have the following code:


DataSet myDataSet = new DataSet();

OleDbDataAdapter adapter = new
OleDbDataAdapter(sb.ToString(),myConn);

adapter.MissingSchemaAction =
MissingSchemaAction.AddWithKey;

int count = adapter.Fill(myDataSet,"ihrawdata");

foreach (DataTable table in myDataSet.Tables)
{
foreach (DataRow row in table.Rows)
{
return Convert.ToString(row[0]);
}
}
return "NONE";
}

Andrew,

I don't mean to be insulting, but that's some odd code. Why are you
"return"ing from w/i the foreach loop? Is the OleDbConnection
"myconn" not being closed properly because of the return statement?


Chris.
 
A

Andrew Mueller

No insult taken... I know I don't have to go through the foreach statements
like I did, but this is all testing code and I have not made it 'look
pretty' yet. I can certainly move the return statement out of the foreach if
that helps..

I was told that the adapter will open and close the connection for me in
another posting, so I took that out. It had no effect on the situation at
all.

Thanks,

Andrew Mueller


Chris R. Timmons said:
Hello,

I have the following code:


DataSet myDataSet = new DataSet();

OleDbDataAdapter adapter = new
OleDbDataAdapter(sb.ToString(),myConn);

adapter.MissingSchemaAction =
MissingSchemaAction.AddWithKey;

int count = adapter.Fill(myDataSet,"ihrawdata");

foreach (DataTable table in myDataSet.Tables)
{
foreach (DataRow row in table.Rows)
{
return Convert.ToString(row[0]);
}
}
return "NONE";
}

Andrew,

I don't mean to be insulting, but that's some odd code. Why are you
"return"ing from w/i the foreach loop? Is the OleDbConnection
"myconn" not being closed properly because of the return statement?


Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top