I have a class that inserts a TextBox value and a FileUpload image into the SQL Server. I’m executing all the class in the Wizard1_FinishButtonClick event. I have 4 steps in Wizard. All the classes are getting executed and inserted other than InsertCert() class.
I executed same codes in a simple .aspx page and the values are inserting into the DB.
Where ‘m I going wrong? Following is the class and Wizard1_FinishButtonClick.
public void Insertcert()
{
String KKStech = @"Data Source=USER-PC\SQLEXPRESS;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();
}
}
This is the final class where all the classes are inserted.
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
InsertInfo();
Insertcert();
Insertaddress();
Insertskills();
}
Put the cursor on the “if (FileUpload1.HasFile)” line and hit F9; this will put a breakpoint on that line (you’ll see a red circle in the left hand margin). Now debug your program (F5). When the breakpoint is hit, hover the mouse over the “HasFile” and you should see a tool tip which gives the value. If the value is false, this explains why the insert is not happening.