My issue is that everytime I try to update in my CMS, it simply updates EVERY column / row.
For example:
I update Test 1 -> Test 2
Meanwhile I have Test 4
But then Test 4 -> Test 2 due to I changed Test 1 to 2 it simply changes that aswell.
They still work by ID correctly, and when I delete them, they delete individually, so the only function that is overlapping with everything is update.
I will now post my code (this is what I have learned, do not comment on security or w/e) simply need this issue fixed so it only updates the selected ID row.
First:
public DataRow GetById(string ID)
{
strSQL = "SELECT ID, clnOverskrift, clnTekst "
+ "FROM tblForside "
+ "WHERE ID=@ID";
objCMD = new MySqlCommand(strSQL);
objCMD.Parameters.AddWithValue("@ID", ID);
return objData.GetData(objCMD, objCon).Rows[0];
}
public void Update(PropertyForside Pro)
{
strSQL = "UPDATE tblForside SET "
+ " clnOverskrift=@Overskrift, clnTekst=@Tekst ";
objCMD = new MySqlCommand(strSQL);
objCMD.Parameters.AddWithValue("@Overskrift", Pro.Overskrift);
objCMD.Parameters.AddWithValue("@Tekst", Pro.Tekst);
objData.ModifyData(objCMD, objCon);
}
I will use both GetById and Update thats why I included both. if you need to know more in this "factory" i will post it.
Here i get it:
FactoryForside fac = new FactoryForside();
PropertyForside Pro = new PropertyForside();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataRow dr = fac.GetById(Request.QueryString["ID"]);
txtOverskrift.InnerText = dr["clnOverskrift"].ToString();
txtText.InnerText = dr["clnTekst"].ToString();
}
}
protected void btnGem_Click(object sender, EventArgs e)
{
Pro.Overskrift = txtOverskrift.InnerText;
Pro.Tekst = txtText.InnerText;
Pro.ID = int.Parse(Request.QueryString["ID"]);
fac.Update(Pro);
Response.Redirect("RedigerForside.aspx");
}
I use InnerText to use TextAreas with NiceEdit.
Adding new ones work, and deleting as mentioned before - only this updating thing not working correctly.
It displays ID correctly "EditForside.aspx?id=13" in the browser, but it seems to select every other ID aswell
Hope you can help me.