Fileupload图像未插入..

时间:2012-07-30 08:13:33

标签: c# asp.net

我有一个ASP.NET FileUpload控件。在代码隐藏文件中,我使用类来插入值 -

public void Insertcert()
        {
            String KKStech = @"Data Source=USER-PC\SQLEXPRESS;Initial Catalog=KKSTech;Integrated Security=True";
            SqlConnection conn = new SqlConnection(KKStech);

            try
            {
                if (FileUpload1.HasFile)
                {
                    byte[] productImage = FileUpload1.FileBytes;
                    String insertstring2 = @"insert into Cert(CertName, CertLogo)
                                       values(@CertName, @CertLogo)";
                    SqlCommand cmd = new SqlCommand(insertstring2, conn);
                    cmd.CommandText = insertstring2;
                    cmd.CommandType = CommandType.Text;
                    conn.Open();
                    cmd.Parameters.AddWithValue("@CertName", TextBox18.Text);
                    cmd.Parameters.Add("@CertLogo", SqlDbType.VarBinary).Value = productImage;
                    cmd.ExecuteNonQuery();

                }

            }


            finally
            {
                conn.Close();
            }

在这里执行 -

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

我正在使用向导控件来插入员工的认证:

<asp:Wizard ID="Wizard1" runat="server"  
     OnFinishButtonClick="Wizard1_FinishButtonClick" 
        Width="266px" ActiveStepIndex="0">
        <WizardSteps>
            <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 2">
<asp:Label ID="Label19" class="caption" runat="server" Text="Certification Name:"></asp:Label>
            <asp:TextBox ID="TextBox18" class="box" runat="server"></asp:TextBox> <br /><br />

            <asp:Label ID="Label20" class="caption" runat="server" Text="Certification Logo:"></asp:Label>
             <asp:FileUpload ID="FileUpload1" class="box" runat="server" /> <br /><br />

0 个答案:

没有答案