?
Solved

Write Contents of SQL String to the screen in asp.net

Posted on 2011-10-18
10
Medium Priority
?
266 Views
Last Modified: 2012-05-12
I have an update stored procedure that I'm running from an aspx page that is giving me the error "Input string was not in a correct format." How can I write the contents of the sql command to the screen so I can see what's incorrect? I'm using sql server 2005 and vs 2005 and c#.
0
Comment
Question by:Carla Romere
  • 5
  • 4
10 Comments
 
LVL 10

Expert Comment

by:GlobaLevel
ID: 36989193
well if you have access to the sql server run it from there....is your sql paramter that you are reading into the database datacast correctly?
0
 

Author Comment

by:Carla Romere
ID: 36989325
As far as I can tell it is - that's why I want to print out on the screen what's getting sent to SQL.
0
 
LVL 2

Expert Comment

by:Paulmc999
ID: 36989336
well if you have the full version of SQL Server 2005 you should be able to run the profiler and in that see your SQL statement. If you are using SQL 2005 express you can download a free profiler called anjlab

http://sites.google.com/site/sqlprofiler/
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:Carla Romere
ID: 36989345
It's not getting TO the SQL server - that's the problem. I want to see the statement that the page is generating when I hit the submit button.
0
 
LVL 2

Expert Comment

by:Paulmc999
ID: 36989379
well how is it generating the statement, as it is generating it, you cannot place it in a string and display it?
0
 

Author Comment

by:Carla Romere
ID: 36989500
I've looked at the parameters and they appear to be set up correctly. There are two different places on this page where the user can run an update via button click. The first one in the code works. It's the second one that's failing. It's calling all the information for the second one and populating the gridview and existing fields correctly, but when I try to update it's not hitting sql at all - just says the input string was not in a correct format. I've attached my code behind and the aspx page.
using System;
using System.Data;
using System.Data.SqlClient;
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;
using System.Text;

public partial class updpm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        txtPartcode.Focus();
    }

    protected void btnShowpart_Click(object sender, EventArgs e)
    {
        FormView1.Visible = true;
        txtCurrpartcode.Text = txtPartcode.Text;
        btnShowmodify.Visible = true;
        btnCustomerPart.Visible = true;
    }

    protected void btnShowmodify_Click(object sender, EventArgs e)
    {
        btnCustomerPart.Visible = false;
        lblModify.Visible = true;
        lblUpdate.Visible = false;
        panelTop.Visible = false;
        Panel1.Visible = true;
        FormView1.Visible = false;
        btnShowmodify.Visible = false;
        btnShowpart.Visible = false;
        lblSuccess.Visible = false;

        txtCurrUser.Text = User.Identity.Name.Split('\\')[1].ToUpper();

        //Old values

        TextBox Oldpartdesc1 = (TextBox)FormView1.FindControl("PART_DESC_1TextBox");
        txtOldpartdesc1.Text = Oldpartdesc1.Text;

        TextBox Oldpartdesc2 = (TextBox)FormView1.FindControl("PART_DESC_2TextBox");
        txtOldpartdesc2.Text = Oldpartdesc2.Text;

        TextBox Oldunitsales = (TextBox)FormView1.FindControl("UNIT_SALESTextBox");
        txtOldunitsales.Text = Oldunitsales.Text;

        TextBox Oldproductgroup = (TextBox)FormView1.FindControl("PRODUCT_GROUPTextBox");
        txtOldproductgroup.Text = Oldproductgroup.Text;

        TextBox Oldproductclass = (TextBox)FormView1.FindControl("PRODUCT_CLASSTextBox");
        txtOldproductclass.Text = Oldproductclass.Text;

        TextBox Oldproducttype = (TextBox)FormView1.FindControl("PRODUCT_TYPETextBox");
        txtOldproducttype.Text = Oldproducttype.Text;

        TextBox Oldsyspartdetail = (TextBox)FormView1.FindControl("SYS_PART_DETAILTextBox");
        txtOldsyspartdetail.Text = Oldsyspartdetail.Text;

        //New values
        
        TextBox Newpartdesc1 = (TextBox)FormView1.FindControl("PART_DESC_1TextBox");
        txtNewpartdesc1.Text = Newpartdesc1.Text;

        TextBox Newpartdesc2 = (TextBox)FormView1.FindControl("PART_DESC_2TextBox");
        txtNewpartdesc2.Text = Newpartdesc2.Text;

        TextBox Newunitsales = (TextBox)FormView1.FindControl("UNIT_SALESTextBox");
        ddlUnitsales.SelectedValue = Newunitsales.Text;

        TextBox Newproductgroup = (TextBox)FormView1.FindControl("PRODUCT_GROUPTextBox");
        ddlProductgroup.SelectedValue = Newproductgroup.Text;

        TextBox Newproductclass = (TextBox)FormView1.FindControl("PRODUCT_CLASSTextBox");
        ddlProductclass.SelectedValue = Newproductclass.Text;

        TextBox Newproducttype = (TextBox)FormView1.FindControl("PRODUCT_TYPETextBox");
        ddlProducttype.SelectedValue = Newproducttype.Text;

        TextBox Newsyspartdetail = (TextBox)FormView1.FindControl("SYS_PART_DETAILTextBox");
        txtNewsyspartdetail.Text = Newsyspartdetail.Text;
    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (ddlProductgroup.SelectedValue.Length > 0 && ddlProductclass.SelectedValue.Length >0)
        {
            btnConfirm_Click(sender, e);
        }
        else
        {
            Panel2.Visible = true;
            btnConfirm.Visible = true;
            btnUpdate.Visible = false;
            btnDeny.Visible = true;
        }
}
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        if (ddlProductgroup.SelectedValue.Length > 0 && ddlProductclass.SelectedValue.Length > 0)
        {

            SqlConnection conn = new SqlConnection("Server=sdwinsql03v; database=fin_dev; User Id=intranet; Password=intranet");
            SqlCommand command = new SqlCommand("AER_UPDATE_PRODUCT_MASTER", conn);
            command.CommandType = CommandType.StoredProcedure;

            //Old Values

            SqlParameter myOldPART_CODEPrm = new SqlParameter("@PART_CODE", SqlDbType.VarChar);
            myOldPART_CODEPrm.Value = txtCurrpartcode.Text;

            SqlParameter myOldPARTDESC1Prm = new SqlParameter("@OLD_PART_DESC_1", SqlDbType.VarChar);
            myOldPARTDESC1Prm.Value = txtOldpartdesc1.Text;

            SqlParameter myOldPARTDESC2Prm = new SqlParameter("@OLD_PART_DESC_2", SqlDbType.VarChar);
            myOldPARTDESC2Prm.Value = txtOldpartdesc2.Text;

            SqlParameter myOldUNITSALESPrm = new SqlParameter("@OLD_UNIT_SALES", SqlDbType.VarChar);
            myOldUNITSALESPrm.Value = txtOldunitsales.Text;

            SqlParameter myOldPRODUCTGROUPPrm = new SqlParameter("@OLD_PRODUCT_GROUP", SqlDbType.VarChar);
            myOldPRODUCTGROUPPrm.Value = txtOldproductgroup.Text;

            SqlParameter myOldPRODUCTCLASSPrm = new SqlParameter("@OLD_PRODUCT_CLASS", SqlDbType.VarChar);
            myOldPRODUCTCLASSPrm.Value = txtOldproductclass.Text;

            SqlParameter myOldPRODUCTTYPEPrm = new SqlParameter("@OLD_PRODUCT_TYPE", SqlDbType.VarChar);
            myOldPRODUCTTYPEPrm.Value = txtOldproducttype.Text;

            SqlParameter myOldSYSPARTDETAILPrm = new SqlParameter("@OLD_SYS_PART_DETAIL", SqlDbType.Text);
            myOldSYSPARTDETAILPrm.Value = txtOldsyspartdetail.Text;

            //New Values

            SqlParameter myPART_CODEPrm = new SqlParameter("@PART_CODE", SqlDbType.VarChar);
            myPART_CODEPrm.Value = txtCurrpartcode.Text;

            SqlParameter myPARTDESC1Prm = new SqlParameter("@PART_DESC_1", SqlDbType.VarChar);
            myPARTDESC1Prm.Value = txtNewpartdesc1.Text;

            SqlParameter myPARTDESC2Prm = new SqlParameter("@PART_DESC_2", SqlDbType.VarChar);
            myPARTDESC2Prm.Value = txtNewpartdesc2.Text;

            SqlParameter myUNITSALESPrm = new SqlParameter("@UNIT_SALES", SqlDbType.VarChar);
            myUNITSALESPrm.Value = ddlUnitsales.SelectedValue;

            SqlParameter myPRODUCTGROUPPrm = new SqlParameter("@PRODUCT_GROUP", SqlDbType.VarChar);
            myPRODUCTGROUPPrm.Value = ddlProductgroup.SelectedValue;

            SqlParameter myPRODUCTCLASSPrm = new SqlParameter("@PRODUCT_CLASS", SqlDbType.VarChar);
            myPRODUCTCLASSPrm.Value = ddlProductclass.SelectedValue;

            SqlParameter myPRODUCTTYPEPrm = new SqlParameter("@PRODUCT_TYPE", SqlDbType.VarChar);
            myPRODUCTTYPEPrm.Value = ddlProducttype.SelectedValue;

            SqlParameter mySYSPARTDETAILPrm = new SqlParameter("@SYS_PART_DETAIL", SqlDbType.Text);
            mySYSPARTDETAILPrm.Value = txtNewsyspartdetail.Text;

            command.Parameters.Add("@SYS_MODIFY_USER", SqlDbType.Char).Value = User.Identity.Name.Split('\\')[1].ToUpper();

            command.Parameters.Add(myPART_CODEPrm);
            command.Parameters.Add(myOldPARTDESC1Prm);
            command.Parameters.Add(myOldPARTDESC2Prm);
            command.Parameters.Add(myOldUNITSALESPrm);
            command.Parameters.Add(myOldPRODUCTGROUPPrm);
            command.Parameters.Add(myOldPRODUCTCLASSPrm);
            command.Parameters.Add(myOldPRODUCTTYPEPrm);
            command.Parameters.Add(myOldSYSPARTDETAILPrm);

            command.Parameters.Add(myPARTDESC1Prm);
            command.Parameters.Add(myPARTDESC2Prm);
            command.Parameters.Add(myUNITSALESPrm);
            command.Parameters.Add(myPRODUCTGROUPPrm);
            command.Parameters.Add(myPRODUCTCLASSPrm);
            command.Parameters.Add(myPRODUCTTYPEPrm);
            command.Parameters.Add(mySYSPARTDETAILPrm);

            conn.Open();
            int rows = command.ExecuteNonQuery();
            conn.Close();

            FormView1.DataBind();
            Panel1.Visible = false;
            FormView1.Visible = true;
            lblSuccess.Visible = true;
            btnShowmodify.Visible = true;
            btnShowpart.Visible = true;
        }
        else
        {
            if (ddlProductgroup.SelectedValue.Length == 0)
            { lblProductgroupblank.Visible = true; }

            if (ddlProductclass.SelectedValue.Length == 0)
            { lblProductclassblank.Visible = true; }

            if (ddlProducttype.SelectedValue.Length == 0)
            { lblProducttypeblank.Visible = true; }

            lblFailed.Visible = true;
        }
    }
    protected void btnDeny_Click(object sender, EventArgs e)
    {
        btnDeny.Visible = false;
        btnUpdate.Visible = true;
        btnConfirm.Visible = false;
        Panel2.Visible = false;
        lblModify.Visible = false;
        lblUpdate.Visible = true;
        lblFailed.Visible = false;
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        Page.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true); 
    }

    protected void ddlProductgroup_DataBound(object sender, EventArgs e)
    {
        if (ddlProductgroup.SelectedValue.Length == 0)
        { lblProductgroupblank.Visible = true; }
    }
    protected void ddlProductclass_DataBound(object sender, EventArgs e)
    {
        if (ddlProductclass.SelectedValue.Length == 0)
        { lblProductclassblank.Visible = true; }
    }
    protected void ddlProducttype_DataBound(object sender, EventArgs e)
    {
        if (ddlProducttype.SelectedValue.Length == 0)
        { lblProducttypeblank.Visible = true; }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        panCustPart.Visible = true;
        txtCurrpartcode2.Text = txtPartcode.Text;
        txtCurrUser2.Text = User.Identity.Name.Split('\\')[1].ToUpper();

        GridViewRow itemSelected = GridView1.SelectedRow;
        string Oldcustnbr = itemSelected.Cells[2].Text.ToString();
        txtCustnbr.Text = Oldcustnbr.ToString();
        
        string Oldcustpartcode = itemSelected.Cells[3].Text.ToString();
        txtCustpartcode.Text = Oldcustpartcode.ToString();
        
        string Oldcustdescription = itemSelected.Cells[4].Text.ToString();
        txtCustdescription.Text = Oldcustdescription.ToString();
        
        string Oldcustdtldescription = itemSelected.Cells[5].Text.ToString();
        txtCustdtldescription.Text = Oldcustdtldescription.ToString();

        //string Oldwarehouse = itemSelected.Cells[6].Text.ToString();
        //ddlWarehouse.SelectedValue = Oldwarehouse.ToString();

        string Oldunitsales = itemSelected.Cells[7].Text.ToString();
        ddlUnitsales2.SelectedValue = Oldunitsales.ToString();

        string Oldsalesprice = itemSelected.Cells[8].Text.ToString();
        txtSalesprice.Text = Oldsalesprice.ToString();
    }

    protected void ddlWarehouse_SelectedIndexChanged(object sender, EventArgs e)
    {
        //if (ddlWarehouse.SelectedValue.Length == 0)
        //{ lblWarehouseblank.Visible = true; }

    }
    protected void btnCustomerPart_Click(object sender, EventArgs e)
    {
        GridView1.Visible = true;
        btnCustomerPart.Visible = false;
        FormView1.Visible = false;
        btnShowmodify.Visible = false;
    }
    protected void btnUpdatecustpart_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection("Server=sdwinsql03v; database=fin_dev; User Id=intranet; Password=intranet");
        SqlCommand command = new SqlCommand("AER_UPDATE_CUSTOMER_PART_MASTER", conn);
        command.CommandType = CommandType.StoredProcedure;

        //Old Values

        SqlParameter myOldPART_CODEPrm = new SqlParameter("@PART_CODE", SqlDbType.VarChar);
        myOldPART_CODEPrm.Value = txtCurrpartcode2.Text;

        SqlParameter myOldCUSTOMER_NUMBERPrm = new SqlParameter("@CUSTOMER_NUMBER", SqlDbType.VarChar);
        myOldCUSTOMER_NUMBERPrm.Value = txtCustnbr.Text;

        SqlParameter myOldCUSTOMERSPARTCODEPrm = new SqlParameter("CUSTOMERS_PART_CODE", SqlDbType.VarChar);
        myOldCUSTOMERSPARTCODEPrm.Value = txtCustpartcode.Text;

        SqlParameter myOldDESCRIPTIONPrm = new SqlParameter("@DESCRIPTION", SqlDbType.VarChar);
        myOldDESCRIPTIONPrm.Value = txtCustdescription.Text;

        SqlParameter myOldDETAILDESCRIPTIONPrm = new SqlParameter("@DETAIL_DESCRIPTION", SqlDbType.Text);
        myOldDETAILDESCRIPTIONPrm.Value = txtCustdtldescription.Text;

        SqlParameter myOldUNITSALESPrm = new SqlParameter("@UNIT_SALES", SqlDbType.VarChar);
        myOldUNITSALESPrm.Value = ddlUnitsales2.SelectedValue;

        SqlParameter myOldSALESPRICEPrm = new SqlParameter("@SALES_PRICE", SqlDbType.Decimal);
        myOldSALESPRICEPrm.Precision = 20;
        myOldSALESPRICEPrm.Scale = 4;
        myOldSALESPRICEPrm.Value = txtOldunitsales.Text;

        //New Values

        //SqlParameter myPART_CODEPrm = new SqlParameter("@PART_CODE", SqlDbType.VarChar);
        //myPART_CODEPrm.Value = txtCurrpartcode.Text;

        //SqlParameter myCUSTOMER_NUMBERPrm = new SqlParameter("@CUSTOMER_NUMBER", SqlDbType.VarChar);
        //myCUSTOMER_NUMBERPrm.Value = txtNewpartdesc1.Text;

        SqlParameter myCUSTOMERSPARTCODEPrm = new SqlParameter("@CUSTOMERS_PART_CODE", SqlDbType.VarChar);
        myCUSTOMERSPARTCODEPrm.Value = txtCustpartcode.Text;

        SqlParameter myDESCRIPTIONPrm = new SqlParameter("@DESCRIPTION", SqlDbType.VarChar);
        myDESCRIPTIONPrm.Value = txtCustdescription.Text;

        SqlParameter myDETAILDESCRIPTIONPrm = new SqlParameter("@DETAILDESCRIPTION", SqlDbType.Text);
        myDETAILDESCRIPTIONPrm.Value = txtCustdtldescription.Text;

        SqlParameter myUNITSALESPrm = new SqlParameter("@UNIT_SALES", SqlDbType.VarChar);
        myUNITSALESPrm.Value = ddlUnitsales.SelectedValue;

        SqlParameter mySALESPRICEPrm = new SqlParameter("@SALES_PRICE", SqlDbType.Decimal);
        mySALESPRICEPrm.Precision = 20;
        mySALESPRICEPrm.Scale = 4;
        mySALESPRICEPrm.Value = txtSalesprice.Text;


        //command.Parameters.Add("@SYS_MODIFY_USER", SqlDbType.Char).Value = User.Identity.Name.Split('\\')[1].ToUpper();

        command.Parameters.Add(myOldPART_CODEPrm);
        command.Parameters.Add(myOldCUSTOMER_NUMBERPrm);
        command.Parameters.Add(myOldCUSTOMERSPARTCODEPrm);
        command.Parameters.Add(myOldDESCRIPTIONPrm);
        command.Parameters.Add(myOldDETAILDESCRIPTIONPrm);
        command.Parameters.Add(myOldUNITSALESPrm);
        command.Parameters.Add(myOldSALESPRICEPrm);

        //command.Parameters.Add(myPART_CODEPrm);
        //command.Parameters.Add(myCUSTOMER_NUMBERPrm);
        command.Parameters.Add(myCUSTOMERSPARTCODEPrm);
        command.Parameters.Add(myDESCRIPTIONPrm);
        command.Parameters.Add(myDETAILDESCRIPTIONPrm);
        command.Parameters.Add(myUNITSALESPrm);
        command.Parameters.Add(mySALESPRICEPrm);

        conn.Open();
        //I want to write the statement here 
        int rows = command.ExecuteNonQuery();
        conn.Close();
    }
}

Open in new window

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="updpm.aspx.cs" Inherits="updpm" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Limited Updates to Product Master</title>
    <script src="js/jquery-1.6.4.min.js" type="text/javascript"></script>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <img src="images/AERT_logo.gif" alt="AERT Logo" /><br />
        <br />
        <h3>
            <asp:Label ID="lblUpdate" runat="server" Text="UPDATE PRODUCT MASTER"></asp:Label>
            <asp:Label ID="lblModify" runat="server" Text="MODIFY THIS RECORD" Visible="False"></asp:Label>&nbsp;<asp:Button
                ID="btnReset" runat="server" OnClick="btnReset_Click" Text="Start Over" /></h3>
            <asp:Panel ID="panelTop" runat="server" Width="662px">
        Enter part code to modify and click Submit:&nbsp;&nbsp;<asp:TextBox ID="txtPartcode" runat="server"></asp:TextBox>
        <asp:Button ID="btnShowpart" runat="server" OnClick="btnShowpart_Click" Text="Submit" />
            </asp:Panel>
        &nbsp;

        <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" Visible="False">
            <ItemTemplate>
                <table style="width: 661px">
                    <tr>
                        <td style="width: 197px">
                            PART_CODE</td>
                        <td>
                            <asp:TextBox ID="PART_CODETextBox" runat="server" Text='<%# Bind("PART_CODE") %>'></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td style="width: 197px">
                            PART_DESC_1</td>
                        <td>
                            <asp:TextBox ID="PART_DESC_1TextBox" runat="server" Text='<%# Bind("PART_DESC_1") %>'
                                Width="438px"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td style="width: 197px">
                            PART_DESC_2</td>
                        <td>
                            <asp:TextBox ID="PART_DESC_2TextBox" runat="server" Text='<%# Bind("PART_DESC_2") %>'
                                Width="439px"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td style="width: 197px">
                            UNIT_SALES</td>
                        <td>
                            <asp:TextBox ID="UNIT_SALESTextBox" runat="server" Text='<%# Bind("UNIT_SALES") %>'></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td style="width: 197px">
                            PRODUCT_GROUP</td>
                        <td>
                            <asp:TextBox ID="PRODUCT_GROUPTextBox" runat="server" Text='<%# Bind("PRODUCT_GROUP") %>'></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td style="width: 197px">
                            PRODUCT_CLASS</td>
                        <td>
                            <asp:TextBox ID="PRODUCT_CLASSTextBox" runat="server" Text='<%# Bind("PRODUCT_CLASS") %>'></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td style="width: 197px">
                            PRODUCT_TYPE</td>
                        <td>
                            <asp:TextBox ID="PRODUCT_TYPETextBox" runat="server" Text='<%# Bind("PRODUCT_TYPE") %>'></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td style="width: 197px" valign="top">
                            SYS_PART_DETAIL</td>
                        <td>
                            <asp:TextBox ID="SYS_PART_DETAILTextBox" runat="server" Text='<%# Bind("SYS_PART_DETAIL") %>'
                                TextMode="MultiLine" Width="439px"></asp:TextBox></td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:FormView>
        <asp:Button ID="btnShowmodify" runat="server" OnClick="btnShowmodify_Click" Text="MODIFY THIS PRODUCT MASTER"
            Visible="False" Width="329px" />
        <asp:Button ID="btnCustomerPart" runat="server" OnClick="btnCustomerPart_Click" Text="MODIFY CUSTOMER'S PART MASTER"
            Visible="False" />
        <asp:Panel ID="Panel1" runat="server" Visible="False" Width="708px">
            <table style="width: 685px">
                <tr>
                    <td style="width: 277px">
                        PART_CODE</td>
                    <td style="width: 400px">
                        <asp:TextBox ID="txtCurrpartcode" runat="server" ReadOnly="True"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 277px">
                        CURRENT USER</td>
                    <td style="width: 400px">
                        <asp:TextBox ID="txtCurrUser" runat="server"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 277px">
                        NEW PART DESCRIPTION 1</td>
                    <td style="width: 400px">
                        <asp:TextBox ID="txtNewpartdesc1" runat="server" Width="388px" MaxLength="25"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 277px">
                        NEW PART DESCRIPTION 2</td>
                    <td style="width: 400px">
                        <asp:TextBox ID="txtNewpartdesc2" runat="server" Width="387px" MaxLength="25"></asp:TextBox></td>
                </tr>
                <tr>
                    <td style="width: 277px">
                        NEW UNIT_SALES</td>
                    <td style="width: 400px">
                        <asp:DropDownList ID="ddlUnitsales" runat="server" DataSourceID="SqlDataSource5"
                            DataTextField="UNIT_SALES" DataValueField="UNIT_SALES">
                        </asp:DropDownList>
                        </td>
                </tr>
                <tr>
                    <td style="width: 277px">
                        NEW PRODUCT GROUP</td>
                    <td style="width: 400px">
                        <asp:DropDownList ID="ddlProductgroup" runat="server" DataSourceID="SqlDataSource2"
                            DataTextField="PRODUCT_GROUP" DataValueField="PRODUCT_GROUP" OnDataBound="ddlProductgroup_DataBound">
                        </asp:DropDownList>
                        <asp:Label ID="lblProductgroupblank" runat="server" Font-Bold="True" ForeColor="Red" Text="&nbsp;&nbsp;&nbsp;<<< BLANK (REQUIRED)"
                            Visible="False"></asp:Label></td>
                </tr>
                <tr>
                    <td style="width: 277px">
                        NEW PRODUCT CLASS</td>
                    <td style="width: 400px">
                        <asp:DropDownList ID="ddlProductclass" runat="server" DataSourceID="SqlDataSource3"
                            DataTextField="PRODUCT_CLASS" DataValueField="PRODUCT_CLASS" OnDataBound="ddlProductclass_DataBound">
                        </asp:DropDownList>
                        <asp:Label ID="lblProductclassblank" runat="server" Font-Bold="True" ForeColor="Red" Text="&nbsp;&nbsp;&nbsp;<<< BLANK (REQUIRED)"
                            Visible="False"></asp:Label></td>
                </tr>
                <tr>
                    <td style="width: 277px; height: 28px;">
                        NEW PRODUCT TYPE</td>
                    <td style="height: 28px; width: 400px;">
                        <asp:DropDownList ID="ddlProducttype" runat="server" DataSourceID="SqlDataSource4"
                            DataTextField="PRODUCT_TYPE" DataValueField="PRODUCT_TYPE" OnDataBound="ddlProducttype_DataBound">
                        </asp:DropDownList>
                        <asp:Label ID="lblProducttypeblank" runat="server" Font-Bold="True" ForeColor="Red" Text="&nbsp;&nbsp;&nbsp;<<< BLANK (NOT REQUIRED)"
                            Visible="False"></asp:Label></td>
                </tr>
                <tr>
                    <td style="width: 277px" valign="top">
                        NEW SYS PART DETAIL</td>
                    <td style="width: 400px">
                        <asp:TextBox ID="txtNewsyspartdetail" runat="server" Width="389px" TextMode="MultiLine"></asp:TextBox></td>
                </tr>
            </table>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic"
ErrorMessage="PART DESCRIPTION 1 IS REQUIRED" Font-Bold="True" 
ControlToValidate="txtNewpartdesc1"></asp:RequiredFieldValidator>

            <asp:Panel ID="Panel2" runat="server" Visible="False" Width="683px">
                <strong><span style="color: #3333cc; font-family: Tahoma">You have not selected either
                    a Product Group, Product Class or Product Type for this Part Code. Product Group
                    and Product Class are required fields. Make sure
                    you have selected a value for both
                    of them.</span></strong></asp:Panel>

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
ConnectionString="<%$ ConnectionStrings:fin_devConnectionString %>"
SelectCommand="SELECT * FROM [VW_PRODUCT_GROUPS_LTD] ORDER BY PRODUCT_GROUP"></asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource3" runat="server" 
ConnectionString="<%$ ConnectionStrings:fin_devConnectionString %>"
SelectCommand="SELECT * FROM [VW_PRODUCT_CLASSES_LTD] ORDER BY PRODUCT_CLASS"></asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource4" runat="server" 
ConnectionString="<%$ ConnectionStrings:fin_devConnectionString %>"
SelectCommand="SELECT * FROM [VW_PRODUCT_TYPES_LTD] ORDER BY PRODUCT_TYPE"></asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource5" runat="server" 
ConnectionString="<%$ ConnectionStrings:fin_devConnectionString %>"
SelectCommand="SELECT [UNIT_SALES] FROM [VW_UNIT_SALES_LTD]"></asp:SqlDataSource>

            <asp:Button ID="btnConfirm" runat="server" OnClick="btnConfirm_Click" Text="Yes, leave them blank and update now."
                Visible="False" Width="246px" />&nbsp;<asp:Button ID="btnDeny" runat="server" OnClick="btnDeny_Click"
                    Text="No, I want to correct that." Visible="False" /><br />
            <asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" Text="Update New Values Now" Width="196px" /><br />
                        <asp:TextBox ID="txtOldpartdesc1" runat="server" Width="290px" Visible="False"></asp:TextBox>
                        <asp:TextBox ID="txtOldpartdesc2" runat="server" Width="282px" Visible="False"></asp:TextBox>
            <br />
                        <asp:TextBox ID="txtOldproductgroup" runat="server" Visible="False"></asp:TextBox>
                        <asp:TextBox ID="txtOldproductclass" runat="server" Visible="False"></asp:TextBox><asp:TextBox ID="txtOldproducttype" runat="server" Visible="False"></asp:TextBox>
            <br />
                        <asp:TextBox ID="txtOldunitsales" runat="server" Visible="False"></asp:TextBox>
                        <asp:TextBox ID="txtOldsyspartdetail" runat="server" Width="244px" Visible="False"></asp:TextBox></asp:Panel>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:fin_devConnectionString %>"
SelectCommand="SELECT [PART_CODE], [PART_DESC_1], [PART_DESC_2], [PRODUCT_GROUP], [PRODUCT_CLASS], [PRODUCT_TYPE], [SYS_PART_DETAIL], [UNIT_SALES] FROM [VW_PRODUCT_MASTER_LTD] WHERE ([PART_CODE] = @PART_CODE)">
            <SelectParameters>
                <asp:ControlParameter ControlID="txtPartcode" Name="PART_CODE" PropertyName="Text"
                    Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        
        <asp:Label ID="lblSuccess" runat="server" Font-Bold="True" Font-Size="Large" ForeColor="Red"
            Text="This record was updated successfully." Visible="False"></asp:Label><asp:Label
                ID="lblFailed" runat="server" Font-Bold="True" Font-Size="Large" ForeColor="Red"
                Text="This record was NOT updated. Product Group and Product Class are required."
                Visible="False"></asp:Label>
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
            DataSourceID="SqlDataSource6" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Visible="False">
            <RowStyle BackColor="#E3EAEB" />
            <Columns>
                <asp:CommandField ShowSelectButton="True" ButtonType="Button" />
                <asp:BoundField DataField="PART_CODE" HeaderText="PART_CODE" SortExpression="PART_CODE" />
                <asp:BoundField DataField="CUSTOMER_NUMBER" HeaderText="CUST_NBR" SortExpression="CUSTOMER_NUMBER" />
                <asp:BoundField DataField="CUSTOMERS_PART_CODE" HeaderText="CUST_PART" SortExpression="CUSTOMERS_PART_CODE" />
                <asp:BoundField DataField="DESCRIPTION" HeaderText="DESCRIPTION" SortExpression="DESCRIPTION" />
                <asp:BoundField DataField="DETAIL_DESCRIPTION" HeaderText="DTL_DESC" SortExpression="DETAIL_DESCRIPTION" />
                <asp:BoundField DataField="WAREHOUSE" HeaderText="WAREHOUSE" SortExpression="WAREHOUSE" />
                <asp:BoundField DataField="UNIT_SALES" HeaderText="UNIT_SALES" SortExpression="UNIT_SALES" />
                <asp:BoundField DataField="SALES_PRICE" HeaderText="SALES_PRICE" SortExpression="SALES_PRICE" />
            </Columns>
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#7C6F57" />
            <AlternatingRowStyle BackColor="White" />
            <EmptyDataTemplate>
                <div style="font-weight:bolder; color:Red; font-size:x-large; ">There are no customer parts set up for this part code.</div>
            </EmptyDataTemplate>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:fin_devConnectionString %>"
            SelectCommand="SELECT [PART_CODE], [CUSTOMER_NUMBER], [CUSTOMERS_PART_CODE], [DESCRIPTION], [DETAIL_DESCRIPTION], [WAREHOUSE], [UNIT_SALES], [SALES_PRICE] FROM [VW_PART_MASTER_BY_CUSTOMER] WHERE ([PART_CODE] = @PART_CODE)">
            <SelectParameters>
                <asp:ControlParameter ControlID="txtPartcode" Name="PART_CODE" PropertyName="Text"
                    Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        <br />
        <asp:Panel ID="panCustPart" runat="server" Height="85px" Width="755px" Visible="False">
            <h3>
                MODIFY THIS CUSTOMER'S PART</h3>

                <table style="width: 701px">
                    <tr>
                        <td style="width: 213px">
                            PART CODE</td>
                        <td>
                            <asp:TextBox ID="txtCurrpartcode2" runat="server" ReadOnly="True" /></td>
                    </tr>
                    <tr>
                        <td style="width: 213px">
                            CURRENT USER</td>
                        <td>
                            <asp:TextBox ID="txtCurrUser2" runat="server" ReadOnly="True" /></td>
                    </tr>
                    <tr>
                        <td style="width: 213px">
                            CUSTOMER NUMBER</td>
                        <td>
                            <asp:TextBox ID="txtCustnbr" runat="server" ReadOnly="True"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td style="width: 213px">
                            CUSTOMER'S PART CODE</td>
                        <td>
                            <asp:TextBox ID="txtCustpartcode" runat="server"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td style="width: 213px">
                            DESCRIPTION</td>
                        <td>
                            <asp:TextBox ID="txtCustdescription" runat="server" Width="469px"></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td style="width: 213px">
                            DETAIL DESCRIPTION</td>
                        <td>
                            <asp:TextBox ID="txtCustdtldescription" runat="server" TextMode="MultiLine" Width="470px"></asp:TextBox></td>
                    </tr>
<%--                    <tr>
                        <td style="width: 213px" valign="top">
                            WAREHOUSE</td>
                        <td>
                            <asp:DropDownList ID="ddlWarehouse" runat="server" DataSourceID="SqlDataSource7" DataTextField="WAREHOUSE" DataValueField="WAREHOUSE" OnSelectedIndexChanged="ddlWarehouse_SelectedIndexChanged" AppendDataBoundItems="true">
                            </asp:DropDownList>
                            </td>
                    </tr>
--%>                    <tr>
                        <td style="width: 213px" valign="top">
                            UNIT SALES</td>
                        <td>
                            <asp:DropDownList ID="ddlUnitsales2" runat="server" DataSourceID="SqlDataSource8" DataTextField="UNIT_SALES" DataValueField="UNIT_SALES">
                            </asp:DropDownList></td>
                    </tr>
                    <tr>
                        <td style="width: 213px">
                            SALES PRICE</td>
                        <td>
                            <asp:TextBox ID="txtSalesprice" runat="server" Width="145px"></asp:TextBox></td>
                    </tr>
                </table>
            <br />
            <asp:Button ID="btnUpdatecustpart" runat="server" Text="Update Customer Part" OnClick="btnUpdatecustpart_Click" /></asp:Panel>
        <asp:SqlDataSource ID="SqlDataSource7" runat="server" ConnectionString="<%$ ConnectionStrings:fin_devConnectionString %>"
            SelectCommand="SELECT DISTINCT &#13;&#10;CASE WHEN LEN(WAREHOUSE)=0 THEN ' '&#13;&#10;ELSE WAREHOUSE END AS WAREHOUSE&#13;&#10;FROM dbo.PART_MASTER_BY_CUSTOMER">
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource8" runat="server" ConnectionString="<%$ ConnectionStrings:fin_devConnectionString %>"
            SelectCommand="SELECT DISTINCT [UNIT_SALES] FROM [VW_PART_MASTER_BY_CUSTOMER] ORDER BY [UNIT_SALES]">
        </asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>

Open in new window

0
 
LVL 2

Assisted Solution

by:Paulmc999
Paulmc999 earned 2000 total points
ID: 36989540
Can you check what the dropdownlists are returning text because you are trying to place the value in a varchar? if that isn't it then you need to double check all parameter types match the data you are placing in them.
0
 

Author Comment

by:Carla Romere
ID: 36993373
Ok, I'm not getting the sales price from the page somehow. I've got Response.Write statements in and am getting the correct values for all the boxes except for sales price.

Here is where I get the value from the GridView and place it in a textbox:

        string Oldsalesprice = itemSelected.Cells[8].Text.ToString();
        txtSalesprice.Text = Oldsalesprice.ToString();

Here is where I capture the old value as the old parameter:

        SqlParameter myOldSALESPRICEPrm = new SqlParameter("@SALES_PRICE", SqlDbType.Decimal);
        myOldSALESPRICEPrm.Precision = 20;
        myOldSALESPRICEPrm.Scale = 4;
        myOldSALESPRICEPrm.Value = txtOldunitsales.Text;

Here is where I define the new parameter:

        SqlParameter mySALESPRICEPrm = new SqlParameter("@SALES_PRICE", SqlDbType.Decimal);
        mySALESPRICEPrm.Precision = 20;
        mySALESPRICEPrm.Scale = 4;
        mySALESPRICEPrm.Value = txtSalesprice.Text;

Here is where I add them to the sql command:

        command.Parameters.Add(myOldSALESPRICEPrm);
        command.Parameters.Add(mySALESPRICEPrm);

When I do this:

        Response.Write(myOldPART_CODEPrm.Value + "<br />");
        Response.Write(myOldCUSTOMER_NUMBERPrm.Value + "<br />");
        Response.Write(myOldCUSTOMERSPARTCODEPrm.Value + "<br />");
        Response.Write(myOldDESCRIPTIONPrm.Value + "<br />");
        Response.Write(myOldDETAILDESCRIPTIONPrm.Value + "<br />");
        Response.Write(myOldUNITSALESPrm.Value + "<br />");
        Response.Write(myOldSALESPRICEPrm.Value + "<br />");

I get all the correct values that should be updated in the database, except for the sales price (last one). Are the parameters not created correctly? The field type in SQL is NUMERIC(20,4).
0
 
LVL 2

Accepted Solution

by:
Paulmc999 earned 2000 total points
ID: 36996636
Just a question, should you be using the same parameter name for both (@SALES_PRICE) ??

just asking because i cannot see the SP you are calling so just checking.

*************

Here is where I capture the old value as the old parameter:

        SqlParameter myOldSALESPRICEPrm = new SqlParameter("@SALES_PRICE", SqlDbType.Decimal);

Here is where I define the new parameter:

        SqlParameter mySALESPRICEPrm = new SqlParameter("@SALES_PRICE", SqlDbType.Decimal);

******************
0
 

Author Comment

by:Carla Romere
ID: 36999982
Yes and there were two others that I didn't get the names changed on. I got that corrected and corrected two of the actual variable names in the second section and it's all working correctly now.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month15 days, 5 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question