How do I add an Update Button in Admin to call a function ?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 anos atrás
I added a button in the "\Administration\Modules\Products.ascx" file :



<asp:Button runat="server" Text="UPDATE CATALOG" ID="btnUpdateCat" OnClick="btnUpdateCat_Click" />

        protected void btnUpdateCat_Click(object sender, EventArgs e)
        {
            // NEED TO RUN THIS SQL CODE :
            // exec sp_fulltext_catalog  'ProdCat',  'start_incremental'  ???
        }


I want to be able to Update the Full Text Catalog when that button is click by running :
"sp_fulltext_catalog  'ProdCat',  'start_incremental'' in the database.

I could write the stored procedure :

CREATE PROCEDURE UpdateSearchCatalog
AS
exec sp_fulltext_catalog  'ProdCat',  'start_incremental'


but I'm not sure how I would "call" it in the code.

Anyone have any ideas on how I can do this?  thanks

...
12 anos atrás
MikeMCSD wrote:
I added a button in the "\Administration\Modules\Products.ascx" file :



<asp:Button runat="server" Text="UPDATE CATALOG" ID="btnUpdateCat" OnClick="btnUpdateCat_Click" />

        protected void btnUpdateCat_Click(object sender, EventArgs e)
        {
            // NEED TO RUN THIS SQL CODE :
            // exec sp_fulltext_catalog  'ProdCat',  'start_incremental'  ???
        }


I want to be able to Update the Full Text Catalog when that button is click by running :
"sp_fulltext_catalog  'ProdCat',  'start_incremental'' in the database.

I could write the stored procedure :

CREATE PROCEDURE UpdateSearchCatalog
AS
exec sp_fulltext_catalog  'ProdCat',  'start_incremental'


but I'm not sure how I would "call" it in the code.

Anyone have any ideas on how I can do this?  thanks

...


I'm not familiar with the 1.9 version, but you might try looking at the service and or repository layer for examples on how to connect and call stored procedures. I wouldn't believe SQL code is written in code behind pages, but hidden  several layers down in the repository pattern or something similar.
12 anos atrás
I figured out how to do it :


      protected void btnUpdateSQL_Click(object sender, EventArgs e)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["NopSqlConnection"].ConnectionString;
            using (var conn = new SqlConnection(connectionString))
            using (var command = new SqlCommand("MP_Import_Update", conn) { CommandType = CommandType.StoredProcedure })
            {
                SqlParameter paramReturnValue = new SqlParameter();
                paramReturnValue.ParameterName = "@RETURN_VALUE";
                paramReturnValue.SqlDbType = SqlDbType.Int;
                paramReturnValue.Direction = ParameterDirection.ReturnValue;
                command.Parameters.Add(paramReturnValue);
                command.CommandTimeout = 0;  // added because query was timing out

                conn.Open();
                command.ExecuteNonQuery();
                conn.Close();
                int returnValue = (int)command.Parameters["@RETURN_VALUE"].Value;
                if (returnValue == 555)
                {
                    lblMsg2.Text = " * * * * DATABASE HAS BEEN UPDATED * * * * ";
                }
                else
                {
                    lblMsg2.Text = " * * * * FAILED  * * * *  ERROR CODE : " + returnValue.ToString();
                }
            }
        }

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.