try { FileUpload img = (FileUpload)imgUpload; if (imgUpload.HasFile) { string contentType = img.PostedFile.ContentType; byte[] fileData = new byte[img.PostedFile.InputStream.Length]; img.PostedFile.InputStream.Read(fileData, 0, fileData.Length); SqlConnection con = new SqlConnection(); con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; con.Open(); string sql = "INSERT INTO image(img_name,img_photo) VALUES(@enm, @eimg) SELECT @@IDENTITY"; SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.AddWithValue("@enm", txtEName.Text.Trim()); cmd.Parameters.AddWithValue("@eimg", fileData); int id = Convert.ToInt32(cmd.ExecuteScalar()); lblResult.Text = String.Format("Product ID is {0}", id); } } catch { lblResult.Text = "There was an error"; }
catch (Exception ex){lblResult.Text = ex.ToString();}
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)