Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

SQL Update query not updating record

$
0
0
Hello I was not sure wither to put this in C# or Asp.net. I am having a problem with a SQL update query. It is not updating the record and not throwing any error or exception. I have a INSERT and DELETE query on the same table that
both run successfully. I am very new to SQL so any help would be greatly appreciated. I am not sure of all the code I need
to post so if any more is needed please let me know. Thanks
 public partial class DeletePage : System.Web.UI.Page
    {
        string strTxt1;
        string strTxt2;
        string strTxt3;
        string strTxt4;
        string index;

        protected void Page_Load(object sender, EventArgs e)
        {
            string strValue = Request.QueryString["row"];
            string[] values = strValue.Split('|');
            strTxt1 = values[0];
            strTxt2 = values[1];
            strTxt3 = values[2];
            strTxt4 = values[3];
            index = values[4];
            txtISBN.Text = strTxt1;
            txtTitle.Text = strTxt2;
            txtEdition.Text = strTxt3;
            txtCopyright.Text = strTxt4;
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/default.aspx");
        }

        protected  void btnConfirmDelete_Click(object sender, EventArgs e)
        {
            SqlDataSource1.DeleteCommand = string.Format("DELETE FROM Titles WHERE ISBN='{0}'", txtISBN.Text);
            SqlDataSource1.Delete();
            Response.Redirect("/default.aspx");
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            SqlDataSource1.UpdateCommand = string.Format("UPDATE Titles SET Title='{0}', EditionNumber='{1}', Copyright='{2}' WHERE ISBN='{3}'",
                txtTitle.Text, txtEdition.Text, txtCopyright.Text, txtISBN.Text);
            SqlDataSource1.Update();
            Response.Redirect("/default.aspx");
        }
    }

public partial class NewBook : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Default.aspx");
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            SqlDataSource1.InsertCommand = string.Format("INSERT INTO Titles (ISBN, Title, EditionNumber, Copyright)  VALUES ('{0}', '{1}', '{2}', '{3}')",
                txtISBN.Text, txtTitle.Text, txtEdition.Text, txtCopyright.Text);
            SqlDataSource1.Insert();
            Response.Redirect("/Default.aspx");
        }
    }


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>