Advertisement

08.21.2007 at 04:38AM PDT, ID: 22776368
[x]
Attachment Details

c# / Executing a Stored Procedure from an asp.net page to update a SQL 2005 Table

Asked by amillyard in SQL Server 2005, Programming for ASP.NET, .NET Framework 2.0

Tags: procedure, 2005, sqldatasource, store

HI there,

c# / Executing a Stored Procedure from an asp.net page.

the asp.net form page is as follows:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CreateNewLeadSourceProvider.aspx.cs" Inherits="FORTUNE.LeadSourceProviders.CreateNewLeadSourceProvider" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Button_CreateNewLeadSourceProvider_Click(object sender, EventArgs e)
    {

    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>F.O.R.T.U.N.E. - Lead Source Providers</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <span style="font-family: Arial"><strong><span style="font-size: 14pt">Create a New Lead Source Provider<br />
            <br />
            <br />
        </span></strong>
            Step 1 :: Define New Lead Source Provider Profile<br />
            <br />
            <br />
        </span>
        <asp:Label ID="Label_LeadSourceProviderName" runat="server" Font-Names="Arial" Font-Size="Small"
            Height="20px" Text="Lead Source Provider Name" Width="200px"></asp:Label><span style="font-family: Arial">
            </span>
        <asp:TextBox ID="TextBox_LeadSourceProviderName" runat="server" Font-Names="Arial"
            Font-Size="Small" Width="200px" MaxLength="50"></asp:TextBox><span style="font-family: Arial"><br />
                <br />
            </span>
        <asp:Label ID="Label_CompanyRegisteredName" runat="server" Font-Names="Arial" Font-Size="Small"
            Height="20px" Text="Company Registered Name" Width="200px"></asp:Label><span style="font-family: Arial">
            </span>
        <asp:TextBox ID="TextBox_CompanyRegisteredName" runat="server" Font-Names="Arial"
            Font-Size="Small" Width="200px" MaxLength="50"></asp:TextBox><span style="font-family: Arial"><br />
                <asp:Label ID="Label_CompanyRegistrationNumber" runat="server" Font-Names="Arial"
                    Font-Size="Small" Height="20px" Text="Company Registration Number" Width="200px"></asp:Label><span
                        style="font-family: Arial"> </span>
                <asp:TextBox ID="TextBox_CompanyRegistrationNumber" runat="server" Font-Names="Arial"
                    Font-Size="Small" MaxLength="50"></asp:TextBox><br />
                <span style="font-family: Arial">
                    <br />
                    <asp:Label ID="Label1" runat="server" Font-Names="Arial" Font-Size="Small" Height="20px"
                        Text="VAT Registered" Width="200px"></asp:Label><span style="font-family: Arial">
                            <asp:RadioButton ID="RadioButton_Yes" runat="server" Font-Names="Arial" Font-Size="Small"
                                GroupName="RadioButton_ValueAddTaxRegistrationRef" Text="Yes" />&nbsp; <span style="font-size: 10pt"></span>
                            <asp:RadioButton ID="RadioButton_No" runat="server" Checked="True" Font-Names="Arial"
                                Font-Size="Small" GroupName="RadioButton_ValueAddTaxRegistrationRef" Text="No" /></span><br />
                        <asp:Label ID="Label_ValueAddTaxRegistration" runat="server" Font-Names="Arial" Font-Size="Small"
                            Height="20px" Text="VAT Registration Number" Width="200px"></asp:Label><span style="font-family: Arial">
                            </span>
                        <asp:TextBox ID="TextBox_ValueAddTaxRegistration" runat="server" Font-Names="Arial"
                            Font-Size="Small" MaxLength="50"></asp:TextBox><span style="font-family: Arial"><br />
                            </span>
                        <br />
                        <asp:Label ID="Label_Switchboard" runat="server" Font-Names="Arial" Font-Size="Small"
                            Height="20px" Text="Switchboard" Width="200px"></asp:Label><span style="font-family: Arial">
                            </span>
                        <asp:TextBox ID="TextBox_Switchboard" runat="server" Font-Names="Arial" Font-Size="Small" MaxLength="50"></asp:TextBox><br />
                        <asp:Label ID="Label_LandlineFax" runat="server" Font-Names="Arial" Font-Size="Small"
                            Height="20px" Text="Landline Fax" Width="200px"></asp:Label><span style="font-family: Arial">
                            </span>
                        <asp:TextBox ID="TextBox_LandlineFax" runat="server" Font-Names="Arial" Font-Size="Small" MaxLength="50"></asp:TextBox><span
                            style="font-family: Arial"><br />
                        </span>
                        <br />
                        <asp:Label ID="Label_WebsiteURL" runat="server" Font-Names="Arial" Font-Size="Small"
                            Height="20px" Text="Website URL" Width="200px"></asp:Label><span style="font-family: Arial">
                            </span>
                        <asp:TextBox ID="TextBox_WebsiteURL" runat="server" Font-Names="Arial" Font-Size="Small" Width="200px" MaxLength="50"></asp:TextBox><br />
                        <asp:Label ID="Label_EmailAddress" runat="server" Font-Names="Arial" Font-Size="Small"
                            Height="20px" Text="Email Address" Width="200px"></asp:Label>
                        <asp:TextBox ID="TextBox_EmailAddress" runat="server" Font-Names="Arial" Font-Size="Small" Width="200px" MaxLength="50"></asp:TextBox><br />
                    <br />
                    </span>
                <asp:Label ID="Label_ComplianceConfirmed" runat="server" Font-Names="Arial" Font-Size="Small"
                    Height="20px" Text="Compliance Confirmed" Width="200px"></asp:Label><asp:CheckBox
                        ID="CheckBox_ComplianceConfirmed" runat="server" Font-Names="Arial" Font-Size="Small" /><br />
                <br />
                <br />
            </span>
        <asp:Button ID="Button_CreateNewLeadSourceProvider" runat="server" Text="Create New Lead Source Provider"
            Width="235px" OnClick="Button_CreateNewLeadSourceProvider_Click" />
        &nbsp;&nbsp;
        <asp:Label ID="Label_SubmissionStatus" runat="server" Font-Size="8pt" ForeColor="Red"></asp:Label><br />
        <br />
        <br />
        <span style="font-size: 10pt; font-family: Arial"><strong>Step 1 - Define New Lead Source
            Provider Profile</strong><br />
            Step 2 -
            <asp:HyperLink ID="HyperLink_CreateAddress" runat="server" NavigateUrl="~/LeadSourceProviders/CreateNewLeadSourceProviderAddress.aspx">Create Address</asp:HyperLink><br />
            Step 3 -
            <asp:HyperLink ID="HyperLink_CreateContact" runat="server" NavigateUrl="~/LeadSourceProviders/CreateNewLeadSourceProviderContact.aspx">Create Contact</asp:HyperLink><br />
            Step 4 -
            <asp:HyperLink ID="HyperLink_CreateProduct" runat="server" NavigateUrl="~/LeadSourceProviders/CreateNewLeadSourceProviderProduct.aspx">Create Product</asp:HyperLink></span></div>
    </form>
</body>
</html>



the Stored Procedure as follows:

ALTER PROCEDURE BackOffice.InsertNewLeadSourceProvider

@LeadSourceProviderName      nvarchar(50),
@CompanyRegisteredName      nvarchar(50),
@CompanyRegistrationNumber      nvarchar(50),
@ValueAddTaxRegistered      bit,
@ValueAddTaxRegistrationRef      nvarchar(50),
@Switchboard            nvarchar(50),
@LandlineFax            nvarchar(50),
@WebsiteURL            nvarchar(50),
@EmailAddress            nvarchar(50),
@ComplianceConfirmed            bit

AS
BEGIN

INSERT LeadSourceProviders (LeadSourceProviderName,
      CompanyRegisteredName,                         CompanyRegistrationNumber,                         ValueAddTaxRegistered,                         ValueAddTaxRegistrationRef,
      Switchboard,
      LandlineFax,
      WebsiteURL,
      EmailAddress,
      ComplianceConfirmed)
                                          
VALUES (@LeadSourceProviderName,
                @CompanyRegisteredName,
                @CompanyRegistrationNumber,
                @ValueAddTaxRegistered,
                @ValueAddTaxRegistrationRef,
                @Switchboard,
                @LandlineFax,
                @WebsiteURL,
                @EmailAddress,
                @ComplianceConfirmed)
END


the asp.net form .cs code (i.e. code activated from button submit) as follows:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace FORTUNE.LeadSourceProviders
{
    public partial class CreateNewLeadSourceProvider : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button_CreateNewLeadSourceProvider_Click(object sender, EventArgs e)
        {
            SqlDataSource FORTUNESQLDataSource = new SqlDataSource();
            Label_SubmissionStatus.Text = null;

            FORTUNESQLDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["FORTUNEConnectionString"].ToString();

            FORTUNESQLDataSource.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
            FORTUNESQLDataSource.InsertCommand = "BackOffice.InsertNewLeadSourceProvider";

            FORTUNESQLDataSource.InsertParameters.Add("@LeadSourceProviderName", "Test 1");
            FORTUNESQLDataSource.InsertParameters.Add("@CompanyRegisteredName", "Test 1");
            FORTUNESQLDataSource.InsertParameters.Add("@CompanyRegistrationNumber", "1234567890");
            FORTUNESQLDataSource.InsertParameters.Add("@ValueAddTaxRegistered", "TRUE");
            FORTUNESQLDataSource.InsertParameters.Add("@ValueAddTaxRegistrationRef", "1234567890");
            FORTUNESQLDataSource.InsertParameters.Add("@Switchboard", "1234");
            FORTUNESQLDataSource.InsertParameters.Add("@LandlineFax", "1234");
            FORTUNESQLDataSource.InsertParameters.Add("@WebsiteURL", "test.com");
            FORTUNESQLDataSource.InsertParameters.Add("@EmailAddress", "post@test.com");
            FORTUNESQLDataSource.InsertParameters.Add("@ComplianceConfirmed", "TRUE");

            //FORTUNESQLDataSource.InsertParameters.Add("@LeadSourceProviderName",        TextBox_LeadSourceProviderName.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@CompanyRegisteredName",         TextBox_CompanyRegisteredName.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@CompanyRegistrationNumber",     TextBox_CompanyRegistrationNumber.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@ValueAddTaxRegistered",         TextBox_ValueAddTaxRegistered.Bit);
            //FORTUNESQLDataSource.InsertParameters.Add("@ValueAddTaxRegistrationRef",    TextBox_ValueAddTaxRegistrationRef.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@Switchboard",                   TextBox_Switchboard.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@LandlineFax",                   TextBox_LandlineFax.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@WebsiteURL",                    TextBox_WebsiteURL.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@EmailAddress",                  TextBox_EmailAddress.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("@ComplianceConfirmed",           TextBox_ComplianceConfirmed.Bit);

            //FORTUNESQLDataSource.InsertParameters.Add("ActiveMemberStatus",         CheckBox_ActiveMemberStatus.Text);
            //FORTUNESQLDataSource.InsertParameters.Add("DateTimeStamp",              DateTime.Now.ToString());
            //FORTUNESQLDataSource.InsertParameters.Add("DataEntryUser",              "ADMIN");
            //FORTUNESQLDataSource.InsertParameters.Add("UniqueSessionID",            Session.SessionID);
            //FORTUNESQLDataSource.InsertParameters.Add("UserIPAddress",              Request.UserHostAddress.ToString());

            int RowsAffected = 0;

            try
            {
                RowsAffected = FORTUNESQLDataSource.Insert();
            }
            catch (Exception)
            {
                SQL_FailureHandler();
            }
            finally
            {
                Label_SubmissionStatus.Text = "[ Comitted to Database OK ]";

                FORTUNESQLDataSource = null;
            }

            TextBox_LeadSourceProviderName.Text     = null;
            TextBox_CompanyRegisteredName.Text      = null;
            TextBox_CompanyRegistrationNumber.Text  = null;
            TextBox_ValueAddTaxRegistration.Text    = null;
            TextBox_SwitchboardNumber.Text          = null;
            TextBox_LandlineFax.Text                = null;
            TextBox_WebsiteURL.Text                 = null;
            TextBox_EmailAddress.Text               = null;
            //CheckBox_ActiveMemberStatus.Text        = "FALSE";
       
        }

        private void SQL_FailureHandler()
        {
            // TODO SQL Failure Handler needs to be scripted

            Label_SubmissionStatus.Text = "[ Commit to Database FAILURE ]";
        }
    }
}


The SQL 2005 database table has the same variables names and variable types as described in the Stored Procedure, and all set to allowing 'null' entries for the time being.  The only two extra columns in the database table are:  LeadSourceProvider_ID, int (auto increment) and DateTimeStamp (getDate()) -- bot set to non-null entry status.



the commented out code (on the form c# scripting portion) are the actual field values I would like to pass -- but have 'hard coded' the values in the meantime, trying to isolate where the error is.

The above scripts provide the data entry form ok, the Stored Procedure works fine when executed directly via SQL server (when adding manually the default values when submitting via SQL Server).

The problem is .... that when submitting the form button, the Stored Procedure does not appear to be activated correctly (or passing variable across etc) -- the effect is that nothing is updated to the database table accordingly.

Hopefully I have diligent enough with providing enough supporting evidence to work with.

Your time and efforts with this request for assistance is much apprieated.

Kind regards,
-andrew.Start Free Trial
 
 
[+][-]08.21.2007 at 04:53AM PDT, ID: 19736929

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.21.2007 at 04:58AM PDT, ID: 19736960

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQL Server 2005, Programming for ASP.NET, .NET Framework 2.0
Tags: procedure, 2005, sqldatasource, store
Sign Up Now!
Solution Provided By: manaya8
Participating Experts: 2
Solution Grade: A
 
 
[+][-]08.21.2007 at 05:04AM PDT, ID: 19736983

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 05:08AM PDT, ID: 19737017

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.21.2007 at 05:12AM PDT, ID: 19737048

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 05:22AM PDT, ID: 19737121

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.21.2007 at 05:29AM PDT, ID: 19737170

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 05:32AM PDT, ID: 19737186

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 05:32AM PDT, ID: 19737187

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 05:34AM PDT, ID: 19737200

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.21.2007 at 05:35AM PDT, ID: 19737203

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 05:37AM PDT, ID: 19737215

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.21.2007 at 05:37AM PDT, ID: 19737218

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 05:41AM PDT, ID: 19737243

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 05:47AM PDT, ID: 19737276

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 05:48AM PDT, ID: 19737280

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.21.2007 at 05:48AM PDT, ID: 19737285

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.21.2007 at 05:53AM PDT, ID: 19737308

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 05:59AM PDT, ID: 19737358

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 06:01AM PDT, ID: 19737370

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 06:04AM PDT, ID: 19737395

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 06:04AM PDT, ID: 19737396

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.21.2007 at 06:05AM PDT, ID: 19737399

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 06:07AM PDT, ID: 19737406

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.21.2007 at 06:08AM PDT, ID: 19737418

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.21.2007 at 06:13AM PDT, ID: 19737445

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 06:13AM PDT, ID: 19737450

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 06:17AM PDT, ID: 19737484

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 06:18AM PDT, ID: 19737491

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 06:24AM PDT, ID: 19737549

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 06:28AM PDT, ID: 19737567

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 06:47AM PDT, ID: 19737704

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 06:55AM PDT, ID: 19737778

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.21.2007 at 06:59AM PDT, ID: 19737824

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 07:37AM PDT, ID: 19738213

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 07:53AM PDT, ID: 19738354

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.21.2007 at 08:13AM PDT, ID: 19738580

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_1_20070628