asp.net 在命令执行过程中遇到致命错误,我不确定是命令问题还是连接问题

nxowjjhe  于 12个月前  发布在  .NET
关注(0)|答案(1)|浏览(138)

这是后面的代码,现在是问题,而提交和更新到sql有一个问题。我不知道问题在哪里,它

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            string salesmanName = Session["SalesmanName"] as string;
            string status = Session["Status"] as string;
            string salesmanCode = Session["SalesmanCode"] as string;
            string formNo = Session["FormNo"] as string;
            string coordinate = Session["Coordinate"] as string;
            string custName = Session["CustName"] as string;

            //Clear session variables after retrieval
            Session.Remove("SalesmanName");
            Session.Remove("Status");
            Session.Remove("SalesmanCode");
            Session.Remove("FormNo");
            Session.Remove("Coordinate");
            Session.Remove("CustName");

            salesmanNameTextBox.Text = salesmanName;
            txtStatus.Text = status;
            salesmanCodeTextBox.Text = salesmanCode;
            txtFormNo.Text = formNo;
            txtCoordinate.Text = coordinate;
            txtCustName.Text = custName;

            check_session();
            TimeOutRedirect();
            PopulateCustomerDescriptionDropDown();
            PopulateCreditTermDropDown();
        }

    }

    private void TimeOutRedirect()
    {
        HtmlMeta meta = new HtmlMeta();

        meta.HttpEquiv = "Refresh";

        meta.Content = Convert.ToString(Session.Timeout * 60) + ";url=LoginPage.aspx";

        this.Page.Header.Controls.Add(meta);
    }

    private void check_session()
    {
        try
        {
            //load session user
            GLOBAL.user_id = Session["user_id"].ToString();
            GLOBAL.axPWD = Session["axPWD"].ToString();
            GLOBAL.logined_user_name = Session["logined_user_name"].ToString();
            GLOBAL.user_authority_lvl = Convert.ToInt32(Session["user_authority_lvl"]);
            GLOBAL.page_access_authority = Convert.ToInt32(Session["page_access_authority"]);
            GLOBAL.user_company = Session["user_company"].ToString();
            GLOBAL.module_access_authority = Convert.ToInt32(Session["module_access_authority"]);
            GLOBAL.switch_Company = Session["switch_Company"].ToString();
            GLOBAL.system_checking = Convert.ToInt32(Session["system_checking"]);
            GLOBAL.data_passing = Session["data_passing"].ToString();
        }
        catch
        {
            Response.Redirect("LoginPage.aspx");
        }
    }

    private void PopulateCustomerDescriptionDropDown()
    {
        Axapta DynAx = new Axapta();

        try
        {
            // Connect to Axapta using your existing connection code
            GLOBAL.Company = GLOBAL.switch_Company;
            DynAx.LogonAs(GLOBAL.user_id, GLOBAL.DomainName,
                new System.Net.NetworkCredential(GLOBAL.ProxyUserName, GLOBAL.ProxyPassword, GLOBAL.DomainName),
                GLOBAL.switch_Company, GLOBAL.Language, GLOBAL.ObjectServer, null);

            // Call the method to get customer descriptions
            List<ListItem> customerDescriptionList = get_AxCustomerDescriptions(DynAx);

            // Bind the customer descriptions to the dropdown list
            DropDownListCustomerDescription.DataSource = customerDescriptionList;
            DropDownListCustomerDescription.DataBind();
        }
        catch (Exception ex)
        {
            // Handle exceptions
            // Log or display an error message
        }
        finally
        {
            // Close the Axapta connection
            DynAx.Logoff();
        }
    }

    public List<ListItem> get_AxCustomerDescriptions(Axapta DynAx)
    {
        List<ListItem> customerDescriptionList = new List<ListItem>();

        // Assuming your customer table in Axapta is named "CustTable"
        int CustTable = 30003; // Replace with the correct table number

        AxaptaObject axQuery = DynAx.CreateAxaptaObject("Query");
        AxaptaObject axQueryDataSource = (AxaptaObject)axQuery.Call("addDataSource", CustTable);

        AxaptaObject axQueryRun = DynAx.CreateAxaptaObject("QueryRun", axQuery);

        customerDescriptionList.Add(new ListItem("-- SELECT --", ""));
        while ((bool)axQueryRun.Call("next"))
        {
            AxaptaRecord DynRec = (AxaptaRecord)axQueryRun.Call("Get", CustTable);
            string temp_CustomerClass = DynRec.get_Field("CustomerClass").ToString();
            string temp_ClassDesc = DynRec.get_Field("ClassDesc").ToString();

            // Log or output the values for debugging
            System.Diagnostics.Debug.WriteLine($"Customer Class: {temp_CustomerClass}, Class Description: {temp_ClassDesc}");

            // Combine CustomerClass and ClassDesc and add to the list
            string combinedDescription = $"{temp_CustomerClass} - {temp_ClassDesc}";
            customerDescriptionList.Add(new ListItem(combinedDescription));

            // Dispose of the current record
            DynRec.Dispose();
        }

        return customerDescriptionList;
    }

    private void PopulateCreditTermDropDown()
    {
        Axapta DynAx = new Axapta();

        try
        {
            // Connect to Axapta using your existing connection code
            GLOBAL.Company = GLOBAL.switch_Company;
            DynAx.LogonAs(GLOBAL.user_id, GLOBAL.DomainName,
                new System.Net.NetworkCredential(GLOBAL.ProxyUserName, GLOBAL.ProxyPassword, GLOBAL.DomainName),
                GLOBAL.switch_Company, GLOBAL.Language, GLOBAL.ObjectServer, null);

            // Call the method to get credit terms
            List<ListItem> creditTermList = get_AxCreditTerms(DynAx);

            // Bind the credit terms to the dropdown list
            DropDownListCreditTerm.DataSource = creditTermList;
            DropDownListCreditTerm.DataBind();
        }
        catch (Exception ex)
        {
 
        }
        finally
        {
 
            DynAx.Logoff();
        }
    }

    public List<ListItem> get_AxCreditTerms(Axapta DynAx)
    {
        List<ListItem> creditTermList = new List<ListItem>();

        int CreditTermTable = 276; 

        AxaptaObject axQuery = DynAx.CreateAxaptaObject("Query");
        AxaptaObject axQueryDataSource = (AxaptaObject)axQuery.Call("addDataSource", CreditTermTable);

        AxaptaObject axQueryRun = DynAx.CreateAxaptaObject("QueryRun", axQuery);

        creditTermList.Add(new ListItem("-- SELECT --", ""));
        while ((bool)axQueryRun.Call("next"))
        {
            AxaptaRecord DynRec = (AxaptaRecord)axQueryRun.Call("Get", CreditTermTable);
            string temp_CreditTermDescription = DynRec.get_Field("Description").ToString();

     
            System.Diagnostics.Debug.WriteLine($"Credit Term Description: {temp_CreditTermDescription}");

            creditTermList.Add(new ListItem(temp_CreditTermDescription));

            DynRec.Dispose();
        }

        return creditTermList;
    }

字符串
这就是提交函数

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        MySqlConnection connection = new MySqlConnection(GLOBAL.connStr);
        try
        {
            string query = "UPDATE newcust_details SET " +
            "SalesmanName = @SalesName, SalesmanMark = @SalesMark, status = @Status, " +
            "FormNo = @FN, CustCategory = @CCategory, CustAddress = @CAddress, " +
            "CustProvince = @CProvince, CustPostal = @CPostal, CustCity = @CCity, " +
            "CustTerritory = @CTerritory, CustRegister = @CRegis, CustClass = @CClass, " +
            "CreditTerm = @CTerm, Discount = @Disc, CreditLimit = @CLimit, " +
            "CustVPPP = @CV, CustType = @CType " +
            "WHERE CustName = @CustName";

            MySqlCommand command = new MySqlCommand(query, connection);

                command.Parameters.AddWithValue("@CustName", txtCustName.Text);
                command.Parameters.AddWithValue("@SalesName", salesmanNameTextBox.Text.Trim());
                command.Parameters.AddWithValue("@SalesMark", txtSalesmansMark.Text.Trim());
                command.Parameters.AddWithValue("@FN", txtFormNo.Text.Trim());
                command.Parameters.AddWithValue("@CAddress", customerAddress.Text.Trim());
                command.Parameters.AddWithValue("@CProvince", province.Text.Trim());
                command.Parameters.AddWithValue("@CPostal", postalCode.Text.Trim());
                command.Parameters.AddWithValue("@CCity", city.Text.Trim());
                command.Parameters.AddWithValue("@CRegis", rocRob.Text.Trim());
                command.Parameters.AddWithValue("@CClass", DropDownListCustomerDescription.SelectedValue);
                command.Parameters.AddWithValue("@CTerm", DropDownListCreditTerm.SelectedValue);
                command.Parameters.AddWithValue("@CLimit", creditLimit.Text.Trim());
                command.Parameters.AddWithValue("@CV", vpppYes.Checked ? 1 : 0);

                List<string> customerCategories = new List<string>();
                if (distribution.Checked) customerCategories.Add("Distribution Lubricant under their In-house brand");

                if (WorkShop.Checked) customerCategories.Add("Workshop");

                if (CounterSales.Checked) customerCategories.Add("Counter Sales");

                if (VanSales.Checked) customerCategories.Add("VanSales");

                if (distributors.Checked) customerCategories.Add("Distributors");

                string customerCategoryValue = string.Join(", ", customerCategories);

                command.Parameters.AddWithValue("@CCategory", customerCategoryValue);

                if (privateLimited.Checked)
                    command.Parameters.AddWithValue("@CType", 1);
                else if (publicLimited.Checked)
                    command.Parameters.AddWithValue("@CType", 2);
                else if (soleProprietorship.Checked)
                    command.Parameters.AddWithValue("@CType", 3);
                else if (partnership.Checked)
                    command.Parameters.AddWithValue("@CType", 4);

                connection.Open();
                command.ExecuteNonQuery();
                connection.Close();

            }
            catch (Exception ex)
            {
                Response.Write($"Error: {ex.Message}");
            }
        }

rxztt3cl

rxztt3cl1#

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        MySqlConnection connection = new MySqlConnection(GLOBAL.connStr);
        try
        {
            string query = "UPDATE newcust_details SET " +
                "SalesmanName = @SalesName, SalesmanMark = @SalesMark, status = @Status, " +
                "FormNo = @FN, CustCategory = @CCategory, CustAddress = @CAddress, " +
                "CustProvince = @CProvince, CustPostal = @CPostal, CustCity = @CCity, " +
                "CustTerritory = @CTerritory, CustRegister = @CRegis, CustClass = @CClass, " +
                "CreditTerm = @CTerm, Discount = @Disc, CreditLimit = @CLimit, " +
                "CustVPPP = @CV, CustType = @CType " +
                "WHERE CustName = @CustName";

            MySqlCommand command = new MySqlCommand(query, connection);

            command.Parameters.AddWithValue("@CustName", txtCustName.Text);
            command.Parameters.AddWithValue("@SalesName", salesmanNameTextBox.Text.Trim());
            command.Parameters.AddWithValue("@SalesMark", txtSalesmansMark.Text.Trim());
            command.Parameters.AddWithValue("@Status", txtStatus.Text.Trim());
            command.Parameters.AddWithValue("@FN", txtFormNo.Text.Trim());
            command.Parameters.AddWithValue("@CAddress", customerAddress.Text.Trim());
            command.Parameters.AddWithValue("@CProvince", province.Text.Trim());
            command.Parameters.AddWithValue("@CPostal", postalCode.Text.Trim());
            command.Parameters.AddWithValue("@CCity", city.Text.Trim());
            command.Parameters.AddWithValue("@CRegis", rocRob.Text.Trim());
            command.Parameters.AddWithValue("@CClass", DropDownListCustomerDescription.SelectedValue);
            command.Parameters.AddWithValue("@CTerm", DropDownListCreditTerm.SelectedValue);
            command.Parameters.AddWithValue("@CLimit", creditLimit.Text.Trim());
            command.Parameters.AddWithValue("@CV", vpppYes.Checked ? 1 : 0);
            command.Parameters.AddWithValue("@CTerritory", territory.Text.Trim());
            command.Parameters.AddWithValue("@Disc", chkDiscount.Checked ? 1 : 0);

            List<string> customerCategories = new List<string>();

            if (distribution.Checked)
            {
                customerCategories.Add("Distribution Lubricant under their In-house brand");
            }
            if (WorkShop.Checked)
            {
                customerCategories.Add("Workshop");
            }
            if (CounterSales.Checked)
            {
                customerCategories.Add("Counter Sales");
            }

         

            string customerCategoryValue = string.Join(", ", customerCategories);

            command.Parameters.AddWithValue("@CCategory", customerCategoryValue);

            if (privateLimited.Checked)
                command.Parameters.AddWithValue("@CType", 1);
            else if (publicLimited.Checked)
                command.Parameters.AddWithValue("@CType", 2);
            else if (soleProprietorship.Checked)
                command.Parameters.AddWithValue("@CType", 3);
            else if (partnership.Checked)
                command.Parameters.AddWithValue("@CType", 4);

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
        catch (Exception ex)
        {
            Response.Write($"Error: {ex.Message}<br />");
            Response.Write($"Stack Trace: {ex.StackTrace}<br />");
            Response.Write($"Inner Exception: {ex.InnerException?.Message}<br />");
        }
    }

字符串

相关问题