User talk:Subhashuppdha

///.cs Page

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["masterConnectionString"].ConnectionString);

public void FetchAllImagesInfo //Bind GridView/ {       string sql = "Select * from empDetails"; SqlDataAdapter da = new SqlDataAdapter(sql, con); DataTable dt = new DataTable; da.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind; }   protected void Page_Load(object sender, EventArgs e)    { FetchAllImagesInfo; }

protected void btnSubmit_Click(object sender, EventArgs e)   { if (txtName.Text == "") { return; } if (FleImgUpload.PostedFile.FileName != "") {           string Type = FleImgUpload.PostedFile.ContentType; //if (Type == ".jpg" || Type == ".bmp" || Type == ".gif" || Type==".jpeg") //{ }           //else { //Comment only take this formate //   return; }

try {               con.Open; string sql = "INSERT INTO empDetails (empname,empimg) VALUES(@enm, @eimg)"; SqlCommand cmd = new SqlCommand(sql, con); cmd.Parameters.AddWithValue("@enm", txtName.Text.Trim); cmd.Parameters.AddWithValue("@eimg", FleImgUpload.FileBytes); cmd.ExecuteNonQuery; txtName.Text = ""; txtName.Focus; FetchAllImagesInfo; }           catch (Exception ex) {               ex.Message.ToString; }           finally {               con.Close;

}       }        else { return; }

}

////Genric Handler

public void ProcessRequest(HttpContext context) {       //For Display Imnage SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["masterConnectionString"].ConnectionString); myConnection.Open; string sql = "Select empname, empimg from EmpDetails where empid=@ImageId"; SqlCommand cmd = new SqlCommand(sql, myConnection); cmd.Parameters.Add("@ImageId", SqlDbType.Int).Value = context.Request.QueryString["id"]; cmd.Prepare; SqlDataReader dr = cmd.ExecuteReader; dr.Read; context.Response.ContentType = dr["empname"].ToString; context.Response.BinaryWrite((byte[])dr["empimg"]); dr.Close; myConnection.Close; }

/////Aspx page Design