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?
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 ChongCommented:
you forgot to provide parameter: @compAddressId with its value before you executing the command?
0

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)'
0
Ryan ChongCommented:
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...
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy 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>");
            }
        }
0
Ryan ChongCommented:
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
0
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

0
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'.
0
Ryan ChongCommented:
i changed the Update to this but nothing worked
what's the error now?
0
Ryan ChongCommented:
any response here?
0
JayAuthor Commented:
I think it was because of the parameter !! thanks btw
0
AndyAinscowFreelance programmer / ConsultantCommented:
Did you understand my comment in the end?
0
JayAuthor Commented:
Yea haha
0
JayAuthor Commented:
Thanks for helping !!
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.