2
Reply

Problem with updating gridveiw

ehsan soltani

ehsan soltani

Jun 27 2015 10:17 AM
483

Dear my friends

I created a Gridview which was contained photo and title. I also created a linkbutton to edit the photo and title of gridview. this linkbuttton transfer the usres to the second page to edit the title and photo of gridview. in new page using of programming the photo is changed but the title is not changed.

 the program is :

 protected void Button1_Click(object sender, EventArgs e)

        {

            int id = Convert.ToInt32(Request.QueryString["Code"]);

            string filename = FileUpload1.ToolTip;

            if (FileUpload1.HasFile)

            {

                filename = FileUpload1.FileName;

                FileUpload1.SaveAs(Server.MapPath("pics\\") + filename);

            }

            SqlConnection con = new SqlConnection();

            con.ConnectionString = "Data Source=.;Initial Catalog=tbldms1;Integrated Security=True";

            string q = "update ooo set title=@title,photo=@photo,where id=@id";

            SqlCommand cmd = new SqlCommand(q, con);

            cmd.Parameters.AddWithValue("@id", id);

            cmd.Parameters.AddWithValue("@title", TextBox1.Text);

            cmd.Parameters.AddWithValue("@photo",filename);

            con.Open();

            cmd.ExecuteNonQuery();

            con.Close();

            TextBox1.Text = "";   

        }


Answers (2)