Get image name from image Path from FormView and save in Database using C# in ASP.Net

Last Reply 2 months ago By micah

Posted 2 months ago

 

protected void btnSharenow_Click(object sender, EventArgs e)
  
    {
        string modelId = (SharePost.Row.FindControl("lblModalId") as Label).Text;
        string userName = (SharePost.Row.FindControl("lblUserName") as Label).Text;
        string fuserName = (SharePost.Row.FindControl("lblfUserName") as Label).Text;
        string contentPost = (SharePost.Row.FindControl("lblpost") as Label).Text;
        string comment = (SharePost.Row.FindControl("txtcommentshare") as TextBox).Text;
       string img = (SharePost.Row.FindControl("img") as Image).;

Also i need to insert these correctly but i dont know how to do that

 

private void InsertDatabase(string userName, string fuserName, string contentPost, DateTime sendDate, string modelId, string comment)
    {
        using (SqlConnection con = new SqlConnection(constrr))
        {
            using (SqlCommand cmd = new SqlCommand("INSERT INTO USERPost VALUES(@UserName,@FriendUserName,@ContentPost,,@ImageName1,@SendDate,@ShareId,@Comments,@FriendImageName,@null,@null)", con))
            {
               // cmd.Parameters.AddWithValue("@ShareId", modelId);
                cmd.Parameters.AddWithValue("@UserName", username = this.Page.User.Identity.Name);
                cmd.Parameters.AddWithValue("@FriendUserName", fuserName);
                cmd.Parameters.AddWithValue("@ContentPost", contentPost);
                cmd.Parameters.AddWithValue("@SendDate", sendDate);
                cmd.Parameters.AddWithValue("@ShareId", modelId);
                cmd.Parameters.AddWithValue("@Comments", comment);
                cmd.Parameters.AddWithValue("@FriendImageName", img2);
                cmd.Parameters.AddWithValue("@TotalCount", );
                cmd.Parameters.AddWithValue("@ADStatus", );
                cmd.Parameters.AddWithValue("@ImageName1", umg);
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
            }
        }

 

You are viewing reply posted by: micah 2 months ago.
Posted 2 months ago

Thank you so much for your help, this very last solution worked.

I agree, here is the link: http://e-iceblue.com/free-api