Click here to Skip to main content
15,888,802 members
Home / Discussions / C#
   

C#

 
GeneralRe: Shamless repost - related to delegates Pin
Pete O'Hanlon17-Jun-11 11:00
mvePete O'Hanlon17-Jun-11 11:00 
GeneralRe: Shamless repost - related to delegates Pin
Bibekananda Mallick19-Jun-11 19:08
Bibekananda Mallick19-Jun-11 19:08 
GeneralRe: Shamless repost - related to delegates Pin
Pete O'Hanlon19-Jun-11 23:41
mvePete O'Hanlon19-Jun-11 23:41 
AnswerRe: Shamless repost - related to delegates Pin
PIEBALDconsult17-Jun-11 14:52
mvePIEBALDconsult17-Jun-11 14:52 
QuestionDownloading binaries sockets Pin
krosty478217-Jun-11 7:29
krosty478217-Jun-11 7:29 
AnswerRe: Downloading binaries sockets Pin
Mark Salsbery17-Jun-11 10:22
Mark Salsbery17-Jun-11 10:22 
AnswerRe: Downloading binaries sockets Pin
BobJanova20-Jun-11 0:00
BobJanova20-Jun-11 0:00 
QuestionAsynchronous database callback Pin
Herman<T>.Instance17-Jun-11 5:30
Herman<T>.Instance17-Jun-11 5:30 
I have a small problem with retrieving a DataTable object from an asynchronous call.

My setup:
I have a Winfom app that has a reference to a library.
In the Library I have a class called Run which does:
public static DataTable GetAsyncDataTable(String Query, CommandType sqlCommandType)
       {
           Abstract.AbstractSqlCommand mySqlCommand = new Concrete.ConcreteSqlCommand();

           mySqlCommand.GetAsyncDataTableBegin(Query, sqlCommandType);

           queryDuration = mySqlCommand.queryDuration;
           return mySqlCommand.MyTable;

       }


In the GetAsyncDataTableBegin method the code is
 public override IAsyncResult GetAsyncDataTableBegin(String Query, CommandType sqlCommandType)
        {
            return GetAsyncDataTableBegin(Query, null, sqlCommandType, null);
        }

public override IAsyncResult GetAsyncDataTableBegin(String Query, List<SqlParameter> sqlParameters, CommandType sqlCommandType, String ConnectionString)
        {
            DateTime nu = DateTime.Now;
            SqlCommand command = Get(Query, sqlParameters, sqlCommandType, ConnectionString);
           return command.BeginExecuteReader(GetAsyncDataTableEnd, command, CommandBehavior.CloseConnection);
        }

In the GetAsyncDataTableEnd Method the code is
public override void GetAsyncDataTableEnd(IAsyncResult myResult)
        {
            SqlCommand command = null;
            SqlDataReader dr = null;
            DateTime nu = DateTime.Now;
            DataTable myTable = new DataTable();

            try
            {
                command = (SqlCommand)myResult.AsyncState;
                dr = command.EndExecuteReader(myResult);
                myTable.Load(dr);
                MyTable = myTable; //MyTable is a public override DataTable MyTable (property)
            }
            catch (Exception err)
            {
                String poef = err.ToString();
            }
            finally
            {
                if (null != dr)
                    dr.Close();
                command.Connection.Close();
                DateTime klaar = DateTime.Now;
                queryDuration = (klaar - nu).Duration();
                string Time = queryDuration.ToString();
            }
        }


And now my problem: When I call the Run.GetAsyncDataTable (first code block), my data is retrieved asynchronously in another thread but the lines in Run.GetAsyncDataTable keep on running so
queryDuration is 0:00:00.000 and mySqlCommand.MyTable = null;

I do not want to poll to wait while mySqlCommand.MyTable == null. How can I have the DataTable filled in the Run.GetAsyncDataTable method?
In Word you can only store 2 bytes. That is why I use Writer.

AnswerRe: Asynchronous database callback Pin
BobJanova17-Jun-11 5:39
BobJanova17-Jun-11 5:39 
GeneralRe: Asynchronous database callback Pin
Herman<T>.Instance17-Jun-11 7:38
Herman<T>.Instance17-Jun-11 7:38 
GeneralRe: Asynchronous database callback Pin
BobJanova17-Jun-11 7:41
BobJanova17-Jun-11 7:41 
GeneralRe: Asynchronous database callback Pin
Herman<T>.Instance17-Jun-11 8:03
Herman<T>.Instance17-Jun-11 8:03 
GeneralRe: Asynchronous database callback Pin
BobJanova17-Jun-11 8:09
BobJanova17-Jun-11 8:09 
GeneralRe: Asynchronous database callback Pin
Herman<T>.Instance17-Jun-11 8:36
Herman<T>.Instance17-Jun-11 8:36 
QuestionTime Sheet software Pin
dipuks17-Jun-11 3:09
dipuks17-Jun-11 3:09 
AnswerRe: Time Sheet software Pin
Pete O'Hanlon17-Jun-11 3:23
mvePete O'Hanlon17-Jun-11 3:23 
GeneralRe: Time Sheet software Pin
dipuks17-Jun-11 5:02
dipuks17-Jun-11 5:02 
AnswerRe: Time Sheet software Pin
Not Active17-Jun-11 3:27
mentorNot Active17-Jun-11 3:27 
GeneralRe: Time Sheet software Pin
Roger Wright17-Jun-11 10:50
professionalRoger Wright17-Jun-11 10:50 
QuestionDateTime to yyyy\MM\dd conversion Pin
Chesnokov Yuriy16-Jun-11 23:03
professionalChesnokov Yuriy16-Jun-11 23:03 
AnswerRe: DateTime to yyyy\MM\dd conversion Pin
Richard MacCutchan16-Jun-11 23:05
mveRichard MacCutchan16-Jun-11 23:05 
AnswerRe: DateTime to yyyy\MM\dd conversion PinPopular
Eraser_stp16-Jun-11 23:14
Eraser_stp16-Jun-11 23:14 
GeneralRe: DateTime to yyyy\MM\dd conversion Pin
Blue_Boy16-Jun-11 23:36
Blue_Boy16-Jun-11 23:36 
GeneralRe: DateTime to yyyy\MM\dd conversion Pin
Eraser_stp17-Jun-11 0:19
Eraser_stp17-Jun-11 0:19 
AnswerRe: DateTime to yyyy\MM\dd conversion Pin
Blue_Boy16-Jun-11 23:39
Blue_Boy16-Jun-11 23:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.