How do i minus data from the program to the database?

I have quantity and description in my database. The quantity will be 100, and the description of it will be A.

When i type in my program like this (after run the program): The quantity is 50. and the description of it is A.

The database: The quantity will be 50 (because minus with the database and my program "100 - 50 = 50", and the description still remains same as A.

How do i do that?

Thanks in advance!

Edit:

I already did like this:

private void UpdateDatas()
        {
            int codeValue = 0;
            int index = 0;

            if (firstForm.textBox1.Text == "Seranne")
            {
                string query = "SELECT [Quantity], [Description], [Price] FROM [Seranne] WHERE [Code] IN (";

                OleDbDataReader dReader;
                OleDbConnection conn = new OleDbConnection(connectionString);
                conn.Open();

                if (int.TryParse(this.textBoxCodeContainer[0].Text, out codeValue))
                {
                    query = query + codeValue.ToString();
                }

                for (int i = 1; i < 17; i++)
                {
                    if (int.TryParse(this.textBoxCodeContainer[i].Text, out codeValue))
                    {
                        query = query + "," + codeValue.ToString();
                    }
                }

                query = query + ")";

                OleDbCommand cmd = new OleDbCommand(query, conn);

                cmd.Parameters.Add("Code", System.Data.OleDb.OleDbType.Integer);
                cmd.Parameters.Add("Quantity", System.Data.OleDb.OleDbType.Integer);

                dReader = cmd.ExecuteReader();

                while (dReader.Read())
                {
                    if (textBoxCodeContainer[index].TextLength != 0)
                    {
                        this.textBoxQuantityContainer[index].Value = Convert.ToDecimal(dReader["Quantity"].ToString());
                        this.textBoxDescContainer[index].Text = dReader["Description"].ToString();
                        this.textBoxSubTotalContainer[index].Text = dReader["Price"].ToString();
                    }

                    if (textBoxQuantityContainer[index].Value != 0)
                    {
                        if (textBoxQuantityContainer[index].Value >= Convert.ToDecimal(dReader["Quantity"].ToString()))
                        {
                             decimal newVal = textBoxQuantityContainer[index].Value - Convert.ToDecimal(dReader["Quantity"].ToString());
                             cmd = new OleDbCommand("UPDATE [Seranne] SET [Quantity] ='" + newVal + "' WHERE [Code] IN (");
                        }
                    }

                    index += 1;
                }

                dReader.Close();
                conn.Close();
            }
        }

        private void AddObjects(object sender, EventArgs e, Form theForm)
        {
            if (firstForm.textBox1.Text == "Fuhans")
            {
                textBoxQuantityContainer = new List<NumericUpDown>();
                textBoxCodeContainer = new List<NumericTextBox>();
                textBoxDescContainer = new List<TextBox>();
                textBoxSubTotalContainer = new List<TextBox>();
                textBoxTotalContainer = new List<TextBox>();
                textBoxAllTotalContainer = new TextBox();

                OleDbDataReader dReader;
                OleDbConnection conn = new OleDbConnection(connectionString);
                conn.Open();

                OleDbCommand cmd = new OleDbCommand("SELECT [Code] FROM [Fuhans]", conn);

                dReader = cmd.ExecuteReader();

                AutoCompleteStringCollection codesCollection = new AutoCompleteStringCollection();

                while (dReader.Read())
                {
                    string numString = dReader[0].ToString().PadLeft(4, '0');
                    codesCollection.Add(numString);
                }

                dReader.Close();
                conn.Close();
}

Here is the link of the screenshots:

https://www.dropbox.com/s/i29o9r0wwc4zgu2/324303.png

https://www.dropbox.com/s/x4m43wo5axo1xon/324304.png

"Code" displayed in the screenshot above is refer to the database, and also the "Quantity", whenever i type the code that already have in the database, the remaining box are filled up. But, when i change the "Quantity" from 100 to 50, it is automatically refresh the program to back to 100 again.

Thanks in advance!

The problem is with your code at the line 49

decimal newVal = textBoxQuantityContainer[index].Value - Convert.ToDecimal(dReader["Quantity"].ToString());

In order to do a math function(minus) both the data must be numerical. But while retrieving data from database it will be in string format. so your code failed.

Solution:
you have to convert the data to integer and then perform math operations.

int qty1=Convert.ToInt32(dReader["Quantity"].ToString());
int qty2=Convert.ToInt32(textBoxQuantityContainer[index].Value.ToString());

int final_qty=qt1-qy2;

Now store the final_qty in the database...

Hope this helps you...

Have a happie coding...:D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.