locked
executing stored procedures within a source page RRS feed

  • Question

  • 1      // event handler for Button with Layout  
    2     public void SaveButton_Click_Base(object sender, EventArgs args)  
    3     {  
    4  
    5         bool shouldRedirect = true;  
    6         string TargetKey = null;  
    7         string DFKA = null;  
    8         string id = null;  
    9         string value = null;  
    10         try 
    11         {              
    12             DbUtils.StartTransaction();  
    13  
    14             if (!this.IsPageRefresh)  
    15             {  
    16  
    17                 this.TblrfpRecordControl.SaveData();  
    18  
    19             }  
    20             this.CommitTransaction(sender);  
    21             string path = @"\\rgv-bos-3040b\deptdata\rfp\";  
    22             if (this.TblrfpRecordControl.officeid.SelectedItem.Text != "Boston")  
    23             {  
    24                 path += this.TblrfpRecordControl.officeid.SelectedItem.Text;  
    25             }  
    26             else 
    27             {  
    28                 path += this.TblrfpRecordControl.sectorid.SelectedItem.Text;  
    29             }  
    30               
    31             path += @"\Proposals\2008\";  
    32             path += this.TblrfpRecordControl.proposal.Text;  
    33             path += @"_08_";  
    34             path += this.TblrfpRecordControl.DataSource.rfp_id.ToString();  
    35             try 
    36             {  
    37                 System.IO.Directory.CreateDirectory(path);  
    38             }  
    39             catch (Exception ex)  
    40             {  
    41                 //TODO: Do something with the exception                  
    42                 //Response.Write("Exception occured trying to create directory.  Exception information: " + ex.Message);  
    43                 //Response.Write("\r\nIdentitiy = " + System.Threading.Thread.CurrentPrincipal.Identity.Name);  
    44                 //shouldRedirect = false;  
    45             }  
    46             TargetKey = this.Page.Request.QueryString["Target"];  
    47  
    48             if (TargetKey != null)  
    49             {  
    50  
    51                 DFKA = this.Page.Request.QueryString["DFKA"];  
    52                 if (this.TblrfpRecordControl != null && this.TblrfpRecordControl.DataSource != null)  
    53                 {  
    54                     id = this.TblrfpRecordControl.DataSource.rfp_id.ToString();  
    55                     value = this.TblrfpRecordControl.DataSource.GetValue(this.TblrfpRecordControl.DataSource.TableAccess.TableDefinition.ColumnList.GetByAnyName(DFKA)).ToString();  
    56                     if (value == null)  
    57                     {  
    58                         value = id;  
    59                     }  
    60                     BaseClasses.Utils.MiscUtils.RegisterAddButtonScript(this, TargetKey, id, value);  
    61                 }  
    62                 shouldRedirect = false;  
    63  
    64             }  
    65  
    66         }  
    67         catch (Exception ex)  
    68         {  
    69             this.RollBackTransaction(sender);  
    70             shouldRedirect = false;  
    71             this.ErrorOnPage = true;  
    72  
    73             BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this"BUTTON_CLICK_MESSAGE", ex.Message);  
    74         }  
    75         finally 
    76         {  
    77             DbUtils.EndTransaction();  
    78         }  
    79         if (shouldRedirect)  
    80         {  
    81             this.ShouldSaveControlsToSession = true;  
    82             this.RedirectBack();  
    83         }  
    84  
    85         else if (TargetKey != null && !shouldRedirect)  
    86         {  
    87             this.ShouldSaveControlsToSession = true;  
    88             this.CloseWindow(true);  
    89         }  
    90  
    91     }  
    92           
    Hi,
     
    What is the best method for executing a stored procedure from within a C# page?

    I have a page which users add data, and then the application creates folders dynamically (works perfectly).

    I have a stored procedure which returns data to a field (filepath).  I have included my current code.
    • Moved by Peter Ritchie Wednesday, September 17, 2008 3:06 PM Question specific to ASP.NET (Moved from Visual C# Language to Off-Topic Posts (Do Not Post Here))
    Wednesday, September 17, 2008 2:40 PM

Answers