5 Replies - 1229 Views - Last Post: 02 January 2014 - 08:38 AM Rate Topic: -----

#1 shantanu11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-January 14

how can i update my database kindly have a look...this is not working

Posted 02 January 2014 - 07:11 AM

  SqlConnection con = new SqlConnection("Data Source=SHANTANU\\SQLEXPRESS;Initial Catalog=Inventry;Integrated Security=True");
        SqlDataAdapter myadp = new SqlDataAdapter();
        //myadp.SelectCommand = new SqlCommand();
        //myadp.SelectCommand.Connection = con;
        //con.Open();
        //myadp.SelectCommand.CommandText = "select * from purchase where item=@item";
        //myadp.SelectCommand.Parameters.AddWithValue("@item", TextBox1.Text);
        //SqlDataReader mydr;
        //mydr = myadp.SelectCommand.ExecuteReader();
        //con.Close();
         myadp.UpdateCommand = new SqlCommand();
            myadp.UpdateCommand.Connection = con;
            con.Open();
            myadp.UpdateCommand.CommandText = "update purchase set quantity= quantity-'"+(qnt1.Text+qnt2.Text)+"' where item='"+(item1.Text+item2.Text)+"'";
            //myadp.UpdateCommand.CommandText = "update purchase set quantity= quantity-'" + qnt2.Text + "' where item='" + item2.Text+ "'";
            //myadp.UpdateCommand.CommandText = "update purchase set quantity= quantity-'" + qnt3.Text + "' where item='" + item3.Text + "'";
            // myadp.UpdateCommand.Parameters.AddWithValue("@item", TextBox1.Text);
            // myadp.InsertCommand.Parameters.AddWithValue("@rate", TextBox2.Text);
            //myadp.UpdateCommand.Parameters.AddWithValue("quantity", TextBox3.Text);
            int i = myadp.UpdateCommand.ExecuteNonQuery();
            if (i>-1)
            {
                Response.Write("<script>alert('updated')</script>");
            }
            else
            {
                Response.Write("<script>alert('Failed')</script>");
            }
            con.Close();
        }


Is This A Good Question/Topic? 0
  • +

Replies To: how can i update my database kindly have a look...this is not working

#2 DarenR  Icon User is online

  • D.I.C Lover

Reputation: 469
  • View blog
  • Posts: 3,200
  • Joined: 12-January 10

Re: how can i update my database kindly have a look...this is not working

Posted 02 January 2014 - 07:27 AM

what errors are you getting?

what is it doing?
Was This Post Helpful? 0
  • +
  • -

#3 shantanu11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-January 14

Re: how can i update my database kindly have a look...this is not working

Posted 02 January 2014 - 07:32 AM

View PostDarenR, on 02 January 2014 - 07:27 AM, said:

what errors are you getting?

what is it doing?

my DB is not getting updated
actually i have made a table with name "item" and "quantity" i want to update the database when i am selling the product where the query will search the item from the "itm.text" (textbox) and will update (it will minus) the present quantity by the number in the qnt.text(textbox). it is working fine for 1 item but if i m using it for more than 1 product it is not getting updated. rather i am getting the error massage "failed" which i have put in last line of the code.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3526
  • View blog
  • Posts: 12,034
  • Joined: 12-December 12

Re: how can i update my database kindly have a look...this is not working

Posted 02 January 2014 - 07:37 AM

"update purchase set quantity= quantity-'"+(qnt1.Text+qnt2.Text)+"' where

Because you are surrounding something with apostrophes you are attempting to subtract text, which won't work. Remove the apostrophes.

But you should not attempt to add qnt1.Text+qnt2.Text, which will possibly concatenate text, rather than adding two numbers. Convert these two Text-values to numbers if you wish to add them.
Was This Post Helpful? 0
  • +
  • -

#5 shantanu11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-January 14

Re: how can i update my database kindly have a look...this is not working

Posted 02 January 2014 - 07:42 AM

i got my answer anyway
txs all
and sir we can perform the minus in that area.
txs any ways
Was This Post Helpful? 0
  • +
  • -

#6 DarenR  Icon User is online

  • D.I.C Lover

Reputation: 469
  • View blog
  • Posts: 3,200
  • Joined: 12-January 10

Re: how can i update my database kindly have a look...this is not working

Posted 02 January 2014 - 08:38 AM

you will never get an accurate result without converting text input into numbers.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1