方法未在ASP.NET向导中执行



我有一个类,它将TextBox值和FileUpload映像插入SQL Server。我正在执行Wizard1_FinishButtonClick事件中的所有类。我在向导中有4个步骤。除了InsertCert()类之外,所有的类都在执行和插入。我在一个简单的.aspx页面中执行了相同的代码,并且将值插入到DB中。

我哪里错了?下面是类和Wizard1_FinishButtonClick。

public void Insertcert()
        {
            String KKStech = @"Data Source=USER-PCSQLEXPRESS;Initial Catalog=KKSTech;Integrated Security=True";
            SqlConnection conn = new SqlConnection(KKStech);
            String insertstring2 = @"insert into Cert(CertName, CertLogo)
                                       values(@CertName, @CertLogo)";
            SqlCommand cmd = new SqlCommand(insertstring2, conn);
            cmd.CommandText = insertstring2;
            cmd.CommandType = CommandType.Text;
            try
            {
                if (FileUpload1.HasFile)
                {
                    byte[] productImage = FileUpload1.FileBytes;
                    conn.Open();
                    cmd.Parameters.AddWithValue("@CertName", TextBox18.Text);
                    cmd.Parameters.Add("@CertLogo", SqlDbType.VarBinary).Value = productImage;
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
        }

这是插入所有类的最后一个类。

 protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            InsertInfo();
            Insertcert();
            Insertaddress();
            Insertskills();
        }

将光标放在"if(FileUpload1.HasFile)"行,然后按F9;这将在该行上放置一个断点(您将在左侧边距中看到一个红色圆圈)。现在调试您的程序(F5)。当遇到断点时,将鼠标悬停在"HasFile"上,您应该会看到一个给出值的工具提示。如果该值为false,这就解释了为什么没有进行插入。

最新更新