Data not updated in database even though it says "Update successful"

Im using web service, where the data in project B has to be updated in project A,

Heres how i did for the DAL class in project B
 public DataSet UpdateBook(String baddress, String bpostalcode, String bcountry, String saddress, String spostalcode, String scountry, String bcompany, String bcity, String scompany, String scity)
        {
            int result = 0;
            DataSet updateAdd;
            SqlDataAdapter da;
            string queryStr = "UPDATE CompanyAddress"
                + "SET BillingAddress=@billingaddress, BillingPostalCode=@billingpostalcode, BillingCountry=@billingcountry, ShippingAddress=@shippingaddress, ShippingPostalCode=@shippingpostalcode, ShippingCountry=@scountry, BillingCompany=@billingcompany, BillingCity=@billingcity, ShippingCompany=@shippingcompany, ShippingCity=@shippingcity"
                + "WHERE CompAddressId=@compAddressId";
            SqlConnection conn = new SqlConnection(_connStr);
            updateAdd = new DataSet();
            SqlCommand cmd = new SqlCommand(queryStr, conn);
            try
            {
                da = new SqlDataAdapter(queryStr.ToString(), conn);
                da.Fill(updateAdd);
                cmd.Parameters.AddWithValue("@billingaddress", baddress);
                cmd.Parameters.AddWithValue("@billingpostalcode", bpostalcode);
                cmd.Parameters.AddWithValue("@billingcountry", bcountry);
                cmd.Parameters.AddWithValue("@shippingaddress", saddress);
                cmd.Parameters.AddWithValue("@shippingpostalcode", spostalcode);
                cmd.Parameters.AddWithValue("@scountry", scountry);
                cmd.Parameters.AddWithValue("@billingcompany", bcompany);
                cmd.Parameters.AddWithValue("@billingcity", bcity);
                cmd.Parameters.AddWithValue("@shippingcompany", scompany);
                cmd.Parameters.AddWithValue("@shippingcity", scity);
                result = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            finally
            {
                conn.Close();
            }
            return updateAdd;
        }

Open in new window

And the code behind for project A
 protected void btnUpdateAddress_Click(object sender, EventArgs e)
        {
            BllCompAddressBook updateAdd = new BllCompAddressBook();
            int result = 0;
            if (result == 0)
            {
                DataSet ds = updateAdd.UpdateBookList(tb_bAddress.Text, tb_bPostalCode.Text, tb_bCountry.Text, tb_sAddress.Text, tb_sPostalCode.Text, tb_sCountry.Text, tb_bCompany.Text, tb_bCity.Text, tb_sCompany.Text, tb_sCity.Text);
                Response.Write("<script>alert('Update successful');</script>");
            }
            else
            {
                Response.Write("<script>alert('Update NOT successful.');</script>");
            }
        }

Open in new window

Any idea why??
JayAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
you forgot to provide parameter: @compAddressId with its value before you executing the command?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JayAuthor Commented:
Like this?
  public DataSet UpdateBook(int caddressid, String baddress, String bpostalcode, String bcountry, String saddress, String spostalcode, String scountry, String bcompany, String bcity, String scompany, String scity)
        {
            int result = 0;
            DataSet updateAdd;
            SqlDataAdapter da;
            string queryStr = "UPDATE CompanyAddress"
                + "SET BillingAddress=@billingaddress, BillingPostalCode=@billingpostalcode, BillingCountry=@billingcountry, ShippingAddress=@shippingaddress, ShippingPostalCode=@shippingpostalcode, ShippingCountry=@scountry, BillingCompany=@billingcompany, BillingCity=@billingcity, ShippingCompany=@shippingcompany, ShippingCity=@shippingcity"
                + "WHERE CompAddressId=@compAddressId";
            SqlConnection conn = new SqlConnection(_connStr);
            updateAdd = new DataSet();
            SqlCommand cmd = new SqlCommand(queryStr, conn);
            try
            {
                da = new SqlDataAdapter(queryStr.ToString(), conn);
                da.Fill(updateAdd);
                cmd.Parameters.AddWithValue("@compAddressId", caddressid);
                cmd.Parameters.AddWithValue("@billingaddress", baddress);
                cmd.Parameters.AddWithValue("@billingpostalcode", bpostalcode);
                cmd.Parameters.AddWithValue("@billingcountry", bcountry);
                cmd.Parameters.AddWithValue("@shippingaddress", saddress);
                cmd.Parameters.AddWithValue("@shippingpostalcode", spostalcode);
                cmd.Parameters.AddWithValue("@scountry", scountry);
                cmd.Parameters.AddWithValue("@billingcompany", bcompany);
                cmd.Parameters.AddWithValue("@billingcity", bcity);
                cmd.Parameters.AddWithValue("@shippingcompany", scompany);
                cmd.Parameters.AddWithValue("@shippingcity", scity);
                result = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            finally
            {
                conn.Close();
            }
            return updateAdd;
        }

Open in new window

I did that, but my project A has an error!!
there are red lines at UpdateBookList(1); part
I dont have a textbox id, so i did it like:
 protected void btnUpdateAddress_Click(object sender, EventArgs e)
        {
            BllCompAddressBook updateAdd = new BllCompAddressBook();
            int result = 0;
            if (result == 0)
            {
                DataSet ds = updateAdd.UpdateBookList(1);
                ds = updateAdd.UpdateBookList(Convert.ToInt32(ds.Tables[0].Rows[0][0]) , tb_bAddress.Text, tb_bPostalCode.Text, tb_bCountry.Text, tb_sAddress.Text, tb_sPostalCode.Text, tb_sCountry.Text, tb_bCompany.Text, tb_bCity.Text, tb_sCompany.Text, tb_sCity.Text);
                Response.Write("<script>alert('Update successful');</script>");
            }
            else
            {
                Response.Write("<script>alert('Update NOT successful.');</script>");
            }
        }

Open in new window

The error is : There is no argument given that corresponds to the required formal parameter 'baddress' of 'BllCompAddressBook.UpdateBookList(int, string, string, string, string, string, string, string, string, string, string)'
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
the error is with UpdateBookList, try debug it.

but do you want to execute it? or you want to execute the UpdateBook?

both are different methods...
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

AndyAinscowFreelance programmer / ConsultantCommented:
This code is very odd.  The first section of code ( "Update Successful" ) will always be run, the ( "Update NOT Successful" ) never runs.

protected void btnUpdateAddress_Click(object sender, EventArgs e)
        {
            BllCompAddressBook updateAdd = new BllCompAddressBook();
           int result = 0;
            if (result == 0)
           {
                DataSet ds = updateAdd.UpdateBookList(tb_bAddress.Text, tb_bPostalCode.Text, tb_bCountry.Text, tb_sAddress.Text, tb_sPostalCode.Text, tb_sCountry.Text, tb_bCompany.Text, tb_bCity.Text, tb_sCompany.Text, tb_sCity.Text);
                Response.Write("<script>alert('Update successful');</script>");
            }
            else
            {
                Response.Write("<script>alert('Update NOT successful.');</script>");
            }
        }
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
the ( "Update NOT Successful" ) never runs.

reason being you put that output in the “else” condition.

in your code, you got:

>>int result = 0;
>>            if (result == 0)

it wil always execute whatever within that condition. things not in that condition with a else statement wil not be executed
JayAuthor Commented:
i changed the Update to this but nothing worked :(
        public int UpdateBook(int addressid, String baddress, String bpostalcode, String bcountry, String saddress, String spostalcode, String scountry, String bcompany, String bcity, String scompany, String scity)
        {
            StringBuilder sql;
            SqlCommand sqlCmd;
            int result;
            result = 0;
            sql = new StringBuilder();
            sql.AppendLine("UPDATE CompanyAddress");
            sql.AppendLine(" ");
            sql.AppendLine("SET BillingAddress=@billingaddress, BillingPostalCode=@billingpostalcode, BillingCountry=@billingcountry, ShippingAddress=@shippingaddress, ShippingPostalCode=@shippingpostalcode, ShippingCountry=@scountry, BillingCompany=@billingcompany, BillingCity=@billingcity, ShippingCompany=@shippingcompany, ShippingCity=@shippingcity");
            sql.AppendLine(" ");
            sql.AppendLine("WHERE CompAddressId=@compAddressId");
            SqlConnection conn = dbConn.GetConnection();
            try
            {
                sqlCmd = new SqlCommand(sql.ToString(), conn);
                sqlCmd.Parameters.AddWithValue("@compAddressId", addressid);
                sqlCmd.Parameters.AddWithValue("@billingaddress", baddress);
                sqlCmd.Parameters.AddWithValue("@billingpostalcode", bpostalcode);
                sqlCmd.Parameters.AddWithValue("@billingcountry", bcountry);
                sqlCmd.Parameters.AddWithValue("@shippingaddress", saddress);
                sqlCmd.Parameters.AddWithValue("@shippingpostalcode", spostalcode);
                sqlCmd.Parameters.AddWithValue("@scountry", scountry);
                sqlCmd.Parameters.AddWithValue("@billingcompany", bcompany);
                sqlCmd.Parameters.AddWithValue("@billingcity", bcity);
                sqlCmd.Parameters.AddWithValue("@shippingcompany", scompany);
                sqlCmd.Parameters.AddWithValue("@shippingcity", scity);
                result = sqlCmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            finally
            {
                conn.Close();
            }

            return result;
        }

Open in new window


And also
   protected void btnUpdateAddress_Click(object sender, EventArgs e)
        {
            BllCompAddressBook updateAdd = new BllCompAddressBook();
            int result = 0;
            if (result == 0) { 
                updateAdd.UpdateBookList(int.Parse(lblId.Text), tb_bAddress.Text, tb_bPostalCode.Text, tb_bCountry.Text, tb_sAddress.Text, tb_sPostalCode.Text, tb_sCountry.Text, tb_bCompany.Text, tb_bCity.Text, tb_sCompany.Text, tb_sCity.Text);
          Response.Write("<script>alert('Update successful');</script>");
            }
            //else
            //{
            //    Response.Write("<script>alert('Update NOT successful.');</script>");
            //}
        }

Open in new window

Reason why i have updateboklist is that im using webservice !! so in the BLL folder i have
        DalCompAddressBook Address = new DalCompAddressBook();
public int UpdateBookList(int caddressid, string baddress, string bpostalcode, string bcountry, string saddress, string spostalcode, string scountry, string bcompany, string bcity, string scompany, string scity)
        {
            return Address.UpdateBook(caddressid, baddress, bpostalcode, bcountry, saddress, spostalcode, scountry, bcompany, bcity, scompany, scity);
        }

Open in new window

AndyAinscowFreelance programmer / ConsultantCommented:
You didn't understand my previous comment:
            int result = 0;
            if (result == 0) {

The if statement is always true.  Your code to display the 'Update NOT Successful' will never run in that function, it will always show 'Update Successful'.
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
i changed the Update to this but nothing worked
what's the error now?
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
any response here?
JayAuthor Commented:
I think it was because of the parameter !! thanks btw
AndyAinscowFreelance programmer / ConsultantCommented:
Did you understand my comment in the end?
JayAuthor Commented:
Yea haha
JayAuthor Commented:
Thanks for helping !!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.