1. Нужна помощь с DevExpress GridControl

    Date: 10/06/09     Keywords: no keywords

    Привет!
    Работал ли кто-нибудь с GridControl.AdvBandedGridView? Мне нужно, чтобы в band я мог поместить другой band на один уровень с column. А компонент позволяет в band'е держать или другие band'ы или column'ы, но не то и другое одновременно. Подскажите, как можно обойти это или же сделать визуальную симуляцию такого размещения band и column?

    Source: http://csharp.livejournal.com/105374.html

  2. Нужна помощь с DevExpress GridControl

    Date: 10/06/09     Keywords: no keywords

    Привет!
    Работал ли кто-нибудь с GridControl.AdvBandedGridView? Мне нужно, чтобы в band я мог поместить другой band на один уровень с column. А компонент позволяет в band'е держать или другие band'ы или column'ы, но не то и другое одновременно. Подскажите, как можно обойти это или же сделать визуальную симуляцию такого размещения band и column?

    Source: https://csharp.livejournal.com/105374.html

  3. Application stops owing to callback from unmanaged DLL

    Date: 09/16/09     Keywords: asp, microsoft

    Why does my c# application stop after receiving a callback from unmanaged DLL?

    I've just encountered this very strange problem. And wonder why it could happen.

    The similar situation is described by someone on MSDN-site.
    http://social.msdn.microsoft.com/Forums/en-US/clr/thread/25bd7c1d-373f-4ef7-a64b-a101897b6b9a/

    But nobody there brought a clear explanation of that yet.

    This little article described how to deal with callbacks from unmanaged code.
    http://www.codeproject.com/KB/cs/win32_to_net.aspx
    I think I did everything properly so that the program works well. But it doesn't.
    If necessary, I could share snippets of my code.

    Thank you.

    Source: http://csharp.livejournal.com/105163.html

  4. Application stops owing to callback from unmanaged DLL

    Date: 09/16/09     Keywords: asp, microsoft

    Why does my c# application stop after receiving a callback from unmanaged DLL?

    I've just encountered this very strange problem. And wonder why it could happen.

    The similar situation is described by someone on MSDN-site.
    http://social.msdn.microsoft.com/Forums/en-US/clr/thread/25bd7c1d-373f-4ef7-a64b-a101897b6b9a/

    But nobody there brought a clear explanation of that yet.

    This little article described how to deal with callbacks from unmanaged code.
    http://www.codeproject.com/KB/cs/win32_to_net.aspx
    I think I did everything properly so that the program works well. But it doesn't.
    If necessary, I could share snippets of my code.

    Thank you.

    Source: https://csharp.livejournal.com/105163.html

  5. Beginner's "-=" question

    Date: 09/03/09     Keywords: java

    There are several ways to listen to an event with "+=". As a primarily-Java programmer I'm particulally drawn to the anonymous delegate. But if you want to subsequently remove the listener with -=, how can you identify the object? I guess it is not possible with the anonymous case, but even when you specify

    MyEvent += MyInstanceMethod

    a delegate for the MyInstanceMethod is being created... so will -= MyInstanceMethod remove the same object from the event's colection of listeners? Or do I have to create an explicit "new" instance of a delegate type, keep it on a field and "-=" the field?

    Source: http://csharp.livejournal.com/104768.html

  6. Beginner's "-=" question

    Date: 09/03/09     Keywords: java

    There are several ways to listen to an event with "+=". As a primarily-Java programmer I'm particulally drawn to the anonymous delegate. But if you want to subsequently remove the listener with -=, how can you identify the object? I guess it is not possible with the anonymous case, but even when you specify

    MyEvent += MyInstanceMethod

    a delegate for the MyInstanceMethod is being created... so will -= MyInstanceMethod remove the same object from the event's colection of listeners? Or do I have to create an explicit "new" instance of a delegate type, keep it on a field and "-=" the field?

    Source: https://csharp.livejournal.com/104768.html

  7. Application.Exit() not exiting!

    Date: 08/18/09     Keywords: no keywords

    I have the following:
                    if (userDlg.ShowDialog(this) == DialogResult.Cancel)
                    {
                        Application.Exit();
                    }
    But when I run the code, the application is not exiting when I click the cancel button on the userDlg dialog. Stepping through in the debugger it's hitting the Application.Exit(); line ok, but just carrying on!

    So how can I get the program to terminate (neatly!) at this point?

    Thanks in advance,

    Tim

    Source: http://csharp.livejournal.com/104596.html

  8. Application.Exit() not exiting!

    Date: 08/18/09     Keywords: no keywords

    I have the following:
                    if (userDlg.ShowDialog(this) == DialogResult.Cancel)
                    {
                        Application.Exit();
                    }
    But when I run the code, the application is not exiting when I click the cancel button on the userDlg dialog. Stepping through in the debugger it's hitting the Application.Exit(); line ok, but just carrying on!

    So how can I get the program to terminate (neatly!) at this point?

    Thanks in advance,

    Tim

    Source: https://csharp.livejournal.com/104596.html

  9. NMock2 question

    Date: 07/08/09     Keywords: no keywords



    Is there a way to change what a mock returns from its faked methods or properies after it has been initialised?

    For instance if I am testing myContainer to see if it supports repeated attempts to Add the same Foo instance regardless of the value of the Foo's boolean Bar property I want to do something like

    myMockery = new Mockery();
    myFoo = myMockery.NewMock();
    Stub.On(myFoo).GetProperty("Bar").Will(Return.Value(false));
    myCollection.Add( myFoo );
    Stub.On(myFoo).GetProperty("Bar").Will(Return.Value(true));
    myCollection.Add( myFoo );
    Assert something about myCollection


    But it seems that once you use "Stub.On" any subsequent Stub.On the same object has no effect?

    Source: http://csharp.livejournal.com/104068.html

  10. NMock2 question

    Date: 07/08/09     Keywords: no keywords



    Is there a way to change what a mock returns from its faked methods or properies after it has been initialised?

    For instance if I am testing myContainer to see if it supports repeated attempts to Add the same Foo instance regardless of the value of the Foo's boolean Bar property I want to do something like

    myMockery = new Mockery();
    myFoo = myMockery.NewMock();
    Stub.On(myFoo).GetProperty("Bar").Will(Return.Value(false));
    myCollection.Add( myFoo );
    Stub.On(myFoo).GetProperty("Bar").Will(Return.Value(true));
    myCollection.Add( myFoo );
    Assert something about myCollection


    But it seems that once you use "Stub.On" any subsequent Stub.On the same object has no effect?

    Source: https://csharp.livejournal.com/104068.html

  11. IIS Application config wildcards

    Date: 06/10/09     Keywords: css

    I have an application in IIS where I set up a wildcard so that all file extensions are processed via the .net dll. I did this so that I can process some URL rewriting. I see at the top of the configuration screen where I can specify which extensions should be processed by what processors. What I am wondering is if there is a way to specify an extension that should not be processed by the wildcard. Specifically I know that .jpg, .gif, .css, .png and .js extensions should not go through it. Is there a way to tell IIS to just serve them normally?



    cross posted to a few communities.

    Source: http://csharp.livejournal.com/103725.html

  12. IIS Application config wildcards

    Date: 06/10/09     Keywords: css

    I have an application in IIS where I set up a wildcard so that all file extensions are processed via the .net dll. I did this so that I can process some URL rewriting. I see at the top of the configuration screen where I can specify which extensions should be processed by what processors. What I am wondering is if there is a way to specify an extension that should not be processed by the wildcard. Specifically I know that .jpg, .gif, .css, .png and .js extensions should not go through it. Is there a way to tell IIS to just serve them normally?



    cross posted to a few communities.

    Source: https://csharp.livejournal.com/103725.html

  13. Photo album component.

    Date: 05/08/09     Keywords: no keywords

    Is there a .net photo album component similar to facebook's photo album? Its a cheap gimmick to be sure but I do like the way the next set of photos preloads and scrolls left. I imagine similar functionality could be used to display any grid data. Any suggestions?

    Source: http://csharp.livejournal.com/103000.html

  14. Photo album component.

    Date: 05/08/09     Keywords: no keywords

    Is there a .net photo album component similar to facebook's photo album? Its a cheap gimmick to be sure but I do like the way the next set of photos preloads and scrolls left. I imagine similar functionality could be used to display any grid data. Any suggestions?

    Source: https://csharp.livejournal.com/103000.html

  15. Client-side validation

    Date: 02/27/09     Keywords: html, xml, java, web

    I’m having some “fun” with client-side validation on a roll-my-own BaseValidator subclass.

    My validator is to validate email format and includes the following code (with XMLdoc removed for brevity):

    using System;
    using System.Text.RegularExpressions;
    
    namespace IrisDigital.WebControls.Validation
    {
       [System.Web.UI.ToolboxData("<{0}:EmailValidator runat='server'/>")]
       public class EmailValidator : BaseValidator
       {
          protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
          {
             base.AddAttributesToRender(writer);
    
             if (base.RenderUplevel)
             {
                writer.AddAttribute("evaluationfunction", "CheckEmailFormat");
                writer.AddAttribute("controltovalidate", this.GetControlRenderID(this.ControlToValidate));
             }
          }
    
          protected override bool EvaluateIsValid()
          {
             // ...
          }
    
          protected override void OnPreRender(EventArgs e)
          {
             base.OnPreRender(e);
    
             if (base.RenderUplevel)
             {
                if (!Page.ClientScript.IsClientScriptBlockRegistered("IrisDigital.WebControls.Validation.EmailValidator"))
                {
                   Page.ClientScript.RegisterClientScriptInclude("IrisDigital.WebControls.Validation.EmailValidator",
                      Page.ClientScript.GetWebResourceUrl(this.GetType(), "IrisDigital.WebControls.Validation.EmailValidator.js"));
                }
                this.ClientValidationFunction = "CheckEmailFormat";
             }
          }
    

    Most of the rationale for doing things this way is from an article on CodeProject: RequiredIfValidator — Extending from the BaseValidator class, which does it precisely this way.

    The validator works wonderfully. But the client-side validation never fires.

    The WebResource correctly gets added to the page as a script include (for which I need to have the following line in my AssemblyInfo.cs, in case you were wondering):

    [assembly: System.Web.UI.WebResource("IrisDigital.WebControls.Validation.EmailValidator.js", "text/javascript")]

    , but it just never gets called.

    Anyone got any ideas why?

    Cross-posted to '[info]'ms_dot_net and '[info]'owenblacker.

    Source: http://community.livejournal.com/csharp/102003.html

  16. Client-side validation

    Date: 02/27/09     Keywords: html, xml, java, web

    I’m having some “fun” with client-side validation on a roll-my-own BaseValidator subclass.

    My validator is to validate email format and includes the following code (with XMLdoc removed for brevity):

    using System;
    using System.Text.RegularExpressions;
    
    namespace IrisDigital.WebControls.Validation
    {
       [System.Web.UI.ToolboxData("<{0}:EmailValidator runat='server'/>")]
       public class EmailValidator : BaseValidator
       {
          protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
          {
             base.AddAttributesToRender(writer);
    
             if (base.RenderUplevel)
             {
                writer.AddAttribute("evaluationfunction", "CheckEmailFormat");
                writer.AddAttribute("controltovalidate", this.GetControlRenderID(this.ControlToValidate));
             }
          }
    
          protected override bool EvaluateIsValid()
          {
             // ...
          }
    
          protected override void OnPreRender(EventArgs e)
          {
             base.OnPreRender(e);
    
             if (base.RenderUplevel)
             {
                if (!Page.ClientScript.IsClientScriptBlockRegistered("IrisDigital.WebControls.Validation.EmailValidator"))
                {
                   Page.ClientScript.RegisterClientScriptInclude("IrisDigital.WebControls.Validation.EmailValidator",
                      Page.ClientScript.GetWebResourceUrl(this.GetType(), "IrisDigital.WebControls.Validation.EmailValidator.js"));
                }
                this.ClientValidationFunction = "CheckEmailFormat";
             }
          }
    

    Most of the rationale for doing things this way is from an article on CodeProject: RequiredIfValidator — Extending from the BaseValidator class, which does it precisely this way.

    The validator works wonderfully. But the client-side validation never fires.

    The WebResource correctly gets added to the page as a script include (for which I need to have the following line in my AssemblyInfo.cs, in case you were wondering):

    [assembly: System.Web.UI.WebResource("IrisDigital.WebControls.Validation.EmailValidator.js", "text/javascript")]

    , but it just never gets called.

    Anyone got any ideas why?

    Cross-posted to ms_dot_net and owenblacker.

    Source: http://csharp.livejournal.com/102003.html

  17. Client-side validation

    Date: 02/27/09     Keywords: html, xml, java, web

    I’m having some “fun” with client-side validation on a roll-my-own BaseValidator subclass.

    My validator is to validate email format and includes the following code (with XMLdoc removed for brevity):

    using System;
    using System.Text.RegularExpressions;
    
    namespace IrisDigital.WebControls.Validation
    {
       [System.Web.UI.ToolboxData("<{0}:EmailValidator runat='server'/>")]
       public class EmailValidator : BaseValidator
       {
          protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
          {
             base.AddAttributesToRender(writer);
    
             if (base.RenderUplevel)
             {
                writer.AddAttribute("evaluationfunction", "CheckEmailFormat");
                writer.AddAttribute("controltovalidate", this.GetControlRenderID(this.ControlToValidate));
             }
          }
    
          protected override bool EvaluateIsValid()
          {
             // ...
          }
    
          protected override void OnPreRender(EventArgs e)
          {
             base.OnPreRender(e);
    
             if (base.RenderUplevel)
             {
                if (!Page.ClientScript.IsClientScriptBlockRegistered("IrisDigital.WebControls.Validation.EmailValidator"))
                {
                   Page.ClientScript.RegisterClientScriptInclude("IrisDigital.WebControls.Validation.EmailValidator",
                      Page.ClientScript.GetWebResourceUrl(this.GetType(), "IrisDigital.WebControls.Validation.EmailValidator.js"));
                }
                this.ClientValidationFunction = "CheckEmailFormat";
             }
          }
    

    Most of the rationale for doing things this way is from an article on CodeProject: RequiredIfValidator — Extending from the BaseValidator class, which does it precisely this way.

    The validator works wonderfully. But the client-side validation never fires.

    The WebResource correctly gets added to the page as a script include (for which I need to have the following line in my AssemblyInfo.cs, in case you were wondering):

    [assembly: System.Web.UI.WebResource("IrisDigital.WebControls.Validation.EmailValidator.js", "text/javascript")]

    , but it just never gets called.

    Anyone got any ideas why?

    Cross-posted to ms_dot_net and owenblacker.

    Source: https://csharp.livejournal.com/102003.html

  18. Bundling changes together.

    Date: 02/21/09     Keywords: cms, database, sql, web

    First off, I'll state that I'm working with C# 2008 express edition, SQL Server 2008 Professional edition, and .NET 3.5.

    Second, I'll state that one of the ideas behind this project is to do it without .Net's auto-binding. If it can't be done without auto-binding, it's not going to get done at all, for reasons having to do with extreme customization of the data access code that will be happening way, way down the line. So I need an answer in code, not in designer. Thanks.

    Okay, what I'm doing seems to me to be simple and obvious, but either .Net doesn't agree with me or I'm looking in the wrong place. I have a simple form. It contains a datagridview and three buttons. One button works perfectly--it's the one that closes the form, and we don't need to discuss it here. The other two buttons, however, are giving me fits. They are labelled "save changes" and "cancel".

    The datagridview is bound to a DataTable. This is pretty standard code, I think:

    SqlConnection cnErasmus = new SqlConnection();
                //populate the datatable with the data already in the table.
                tblAuthorType = PopulateDataSet(cnErasmus);
                //Attach DataTable to datagrid.
                dgvAuthorType.DataSource = tblAuthorType;


    (note: it used to be a dataset. I forgot to change the name of the routine.)

    In case you want/need to see the actual filling of the DataTable, I'll put it

            private DataTable PopulateDataSet(SqlConnection cnErasmus)
            {
                string strAuthorTypeSelectQuery = "SELECT AuthType FROM AuthorType";
                using (cnErasmus)
                {
                    using (SqlCommand cmSelectCommand = new SqlCommand(strAuthorTypeSelectQuery, cnErasmus))
                    {
                        CreateConnectionString(cnErasmus);
                        OpenConnection(cnErasmus);
                        using (SqlDataReader theReader = cmSelectCommand.ExecuteReader())
                        {
                            tblAuthorType.Load(theReader);
                            CloseConnection(cnErasmus);
                        }
                    }
                }



    All of this is completely normal. At least, I think it is. Now, the tough part seems to be logging changes. The obvious way to do so, to me (I'm a database guy more than a programmer) is through a transaction object:

    /******************SqlTransaction trnchangeAuthorTypeData = 
           cnErasmus.BeginTransaction("Changes");
                //Must assign both transaction object and connection
                //to Command object for a pending local transaction.
                SqlCommand cmTransactionCommand = cnErasmus.CreateCommand();
                cmTransactionCommand.Connection = cnErasmus;
                cmTransactionCommand.Transaction = trnchangeAuthorTypeData;
                //Whether transaction is committed or rolled back depends
                //on which button the user presses...********************/


    These are the lines just after setting the dgv's data source.

    I've seen this done at least a dozen times in various places on the web, but in every case, the example has some sort of hardcoded INSERT or DELETE statement immediately following, and then a try/catch block with the appropriate transaction.Commit() or transaction.Rollback() statements. The important bit for me is that in every example I've found, all the statements follow one another. It's all very procedural. I want the Commit() or Rollback() to be fired based on which of those buttons gets pressed; the Cancel button will cause a Rollback() and the Save button will cause a Commit(). To me, this seems perfectly logical. My problem is that, unfortunately, trnchangeAuthorTypeData goes out of scope the second we hit the end of that block of code, and so is nowhere to be found when I get to btnSave_Click or btnCancel_Click. Setting it the normal way (trnChancgeAuthorTypeData = new SqlTransaction()) raises an error based on the protection level of SqlTransaction, so I can't declare it the way I declare every other variable. (While no resource I've consulted specifically explains this odd behavior, they all confirm that this is by design.)

    So, after all that, my question is: how do I separate BeginTransaction(), Commit(), and Rollback() into three separate routines? If that's not possible, as I have spent the last twelve hours ascertaining, is there some way other than transactions to make sure that, when the Cancel button is pressed, the system will roll back all changes since either (a) the form was opened or (b) the Save button was last pressed, and that can be done in that manner (with the transaction-analogue starting in the same routine where the datagridview is bound, and finishing in one of the button-press routines)?

    Thanks.

    Source: http://community.livejournal.com/csharp/101781.html

  19. Bundling changes together.

    Date: 02/21/09     Keywords: cms, database, sql, web

    First off, I'll state that I'm working with C# 2008 express edition, SQL Server 2008 Professional edition, and .NET 3.5.

    Second, I'll state that one of the ideas behind this project is to do it without .Net's auto-binding. If it can't be done without auto-binding, it's not going to get done at all, for reasons having to do with extreme customization of the data access code that will be happening way, way down the line. So I need an answer in code, not in designer. Thanks.

    Okay, what I'm doing seems to me to be simple and obvious, but either .Net doesn't agree with me or I'm looking in the wrong place. I have a simple form. It contains a datagridview and three buttons. One button works perfectly--it's the one that closes the form, and we don't need to discuss it here. The other two buttons, however, are giving me fits. They are labelled "save changes" and "cancel".

    The datagridview is bound to a DataTable. This is pretty standard code, I think:

    SqlConnection cnErasmus = new SqlConnection();
                //populate the datatable with the data already in the table.
                tblAuthorType = PopulateDataSet(cnErasmus);
                //Attach DataTable to datagrid.
                dgvAuthorType.DataSource = tblAuthorType;


    (note: it used to be a dataset. I forgot to change the name of the routine.)

    In case you want/need to see the actual filling of the DataTable, I'll put it

            private DataTable PopulateDataSet(SqlConnection cnErasmus)
            {
                string strAuthorTypeSelectQuery = "SELECT AuthType FROM AuthorType";
                using (cnErasmus)
                {
                    using (SqlCommand cmSelectCommand = new SqlCommand(strAuthorTypeSelectQuery, cnErasmus))
                    {
                        CreateConnectionString(cnErasmus);
                        OpenConnection(cnErasmus);
                        using (SqlDataReader theReader = cmSelectCommand.ExecuteReader())
                        {
                            tblAuthorType.Load(theReader);
                            CloseConnection(cnErasmus);
                        }
                    }
                }



    All of this is completely normal. At least, I think it is. Now, the tough part seems to be logging changes. The obvious way to do so, to me (I'm a database guy more than a programmer) is through a transaction object:

    /******************SqlTransaction trnchangeAuthorTypeData = 
           cnErasmus.BeginTransaction("Changes");
                //Must assign both transaction object and connection
                //to Command object for a pending local transaction.
                SqlCommand cmTransactionCommand = cnErasmus.CreateCommand();
                cmTransactionCommand.Connection = cnErasmus;
                cmTransactionCommand.Transaction = trnchangeAuthorTypeData;
                //Whether transaction is committed or rolled back depends
                //on which button the user presses...********************/


    These are the lines just after setting the dgv's data source.

    I've seen this done at least a dozen times in various places on the web, but in every case, the example has some sort of hardcoded INSERT or DELETE statement immediately following, and then a try/catch block with the appropriate transaction.Commit() or transaction.Rollback() statements. The important bit for me is that in every example I've found, all the statements follow one another. It's all very procedural. I want the Commit() or Rollback() to be fired based on which of those buttons gets pressed; the Cancel button will cause a Rollback() and the Save button will cause a Commit(). To me, this seems perfectly logical. My problem is that, unfortunately, trnchangeAuthorTypeData goes out of scope the second we hit the end of that block of code, and so is nowhere to be found when I get to btnSave_Click or btnCancel_Click. Setting it the normal way (trnChancgeAuthorTypeData = new SqlTransaction()) raises an error based on the protection level of SqlTransaction, so I can't declare it the way I declare every other variable. (While no resource I've consulted specifically explains this odd behavior, they all confirm that this is by design.)

    So, after all that, my question is: how do I separate BeginTransaction(), Commit(), and Rollback() into three separate routines? If that's not possible, as I have spent the last twelve hours ascertaining, is there some way other than transactions to make sure that, when the Cancel button is pressed, the system will roll back all changes since either (a) the form was opened or (b) the Save button was last pressed, and that can be done in that manner (with the transaction-analogue starting in the same routine where the datagridview is bound, and finishing in one of the button-press routines)?

    Thanks.

    Source: http://csharp.livejournal.com/101781.html

  20. Bundling changes together.

    Date: 02/21/09     Keywords: cms, database, sql, web

    First off, I'll state that I'm working with C# 2008 express edition, SQL Server 2008 Professional edition, and .NET 3.5.

    Second, I'll state that one of the ideas behind this project is to do it without .Net's auto-binding. If it can't be done without auto-binding, it's not going to get done at all, for reasons having to do with extreme customization of the data access code that will be happening way, way down the line. So I need an answer in code, not in designer. Thanks.

    Okay, what I'm doing seems to me to be simple and obvious, but either .Net doesn't agree with me or I'm looking in the wrong place. I have a simple form. It contains a datagridview and three buttons. One button works perfectly--it's the one that closes the form, and we don't need to discuss it here. The other two buttons, however, are giving me fits. They are labelled "save changes" and "cancel".

    The datagridview is bound to a DataTable. This is pretty standard code, I think:

    SqlConnection cnErasmus = new SqlConnection();
                //populate the datatable with the data already in the table.
                tblAuthorType = PopulateDataSet(cnErasmus);
                //Attach DataTable to datagrid.
                dgvAuthorType.DataSource = tblAuthorType;


    (note: it used to be a dataset. I forgot to change the name of the routine.)

    In case you want/need to see the actual filling of the DataTable, I'll put it

            private DataTable PopulateDataSet(SqlConnection cnErasmus)
            {
                string strAuthorTypeSelectQuery = "SELECT AuthType FROM AuthorType";
                using (cnErasmus)
                {
                    using (SqlCommand cmSelectCommand = new SqlCommand(strAuthorTypeSelectQuery, cnErasmus))
                    {
                        CreateConnectionString(cnErasmus);
                        OpenConnection(cnErasmus);
                        using (SqlDataReader theReader = cmSelectCommand.ExecuteReader())
                        {
                            tblAuthorType.Load(theReader);
                            CloseConnection(cnErasmus);
                        }
                    }
                }



    All of this is completely normal. At least, I think it is. Now, the tough part seems to be logging changes. The obvious way to do so, to me (I'm a database guy more than a programmer) is through a transaction object:

    /******************SqlTransaction trnchangeAuthorTypeData = 
           cnErasmus.BeginTransaction("Changes");
                //Must assign both transaction object and connection
                //to Command object for a pending local transaction.
                SqlCommand cmTransactionCommand = cnErasmus.CreateCommand();
                cmTransactionCommand.Connection = cnErasmus;
                cmTransactionCommand.Transaction = trnchangeAuthorTypeData;
                //Whether transaction is committed or rolled back depends
                //on which button the user presses...********************/


    These are the lines just after setting the dgv's data source.

    I've seen this done at least a dozen times in various places on the web, but in every case, the example has some sort of hardcoded INSERT or DELETE statement immediately following, and then a try/catch block with the appropriate transaction.Commit() or transaction.Rollback() statements. The important bit for me is that in every example I've found, all the statements follow one another. It's all very procedural. I want the Commit() or Rollback() to be fired based on which of those buttons gets pressed; the Cancel button will cause a Rollback() and the Save button will cause a Commit(). To me, this seems perfectly logical. My problem is that, unfortunately, trnchangeAuthorTypeData goes out of scope the second we hit the end of that block of code, and so is nowhere to be found when I get to btnSave_Click or btnCancel_Click. Setting it the normal way (trnChancgeAuthorTypeData = new SqlTransaction()) raises an error based on the protection level of SqlTransaction, so I can't declare it the way I declare every other variable. (While no resource I've consulted specifically explains this odd behavior, they all confirm that this is by design.)

    So, after all that, my question is: how do I separate BeginTransaction(), Commit(), and Rollback() into three separate routines? If that's not possible, as I have spent the last twelve hours ascertaining, is there some way other than transactions to make sure that, when the Cancel button is pressed, the system will roll back all changes since either (a) the form was opened or (b) the Save button was last pressed, and that can be done in that manner (with the transaction-analogue starting in the same routine where the datagridview is bound, and finishing in one of the button-press routines)?

    Thanks.

    Source: https://csharp.livejournal.com/101781.html

Previous page  ||  Next page


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home