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 = "";
}

Narasimha Reddy ChennupalliRank #1,163 · 1.6K reputationPosted Jun 27, 2015, 10:13 AM EDT
If you want to try with inner query below code snippet will help you
SqlConnection con=new SqlConnection(constr);
string q = "update ooo set title=@title,photo=@photo,where id=@id";
SqlCommand cmd = new SqlCommand(q, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
The above code snippet will work fine, try with that.
If you want to try with Stored procedure, below code snippet help you
SqlCommand cmd= new SqlCommand("procedure_name", con); // write your procedure name cnd.Parameters.Add("@title", TextBox1.Text);
// here add your other parameter like id
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
ehsan soltani17 reputationPosted Jun 30, 2015, 3:09 AM EDT