Updating tables while Inner Joined

Get help on databases - MySQL, Oracle, Access, etc.
Post Reply
Bladerunner
Registered User
Posts: 14338
Joined: 04 Sep 2004, 02:00
Processor: i386DX Sooper
Motherboard: A blue one
Graphics card: A red one
Memory: Hard drive
Location: On a Möbius strip
Contact:

Updating tables while Inner Joined

Post by Bladerunner »

Hey everyone,

I'm doing a C# program, the situation is a clothing shop with tables for Clients, Items, and Transactions.

The first part is easy: just creating a C# front end for the Clients and Items.

For the transactions part of the front-end however, fields from both the transactions table as well as the items table should be imported.

All of this works fine, except my third table in the front-end (the custom transactions one), which can't UPDATE due to the fact that it contains an INNER JOIN.

Any ideas on how to circumvent this? I've been trying since saturday, to no avail.

Here's my latest shot at it:

Code: Select all

        private void toolBtnSaveTrans_Click(object sender, EventArgs e)   //Custom Save
        {
            string sTransDate = "", sClientID = "", sDescription = "", sRetailPrice = "";
            bsTrans.EndEdit();

            for (int iRow = 0; iRow <= dgTrans.RowCount - 2; iRow++)
            {
                for (int iCol = 0; iCol <= dgTrans.ColumnCount - 1; iCol++)
                {                   
                    if (iCol == 0)
                    {
                        sTransDate = dgTrans[iCol, iRow].Value.ToString();
                    }

                    else if (iCol == 1)
                    {
                        sClientID = dgTrans[iCol, iRow].Value.ToString();
                    }

                    else if (iCol == 2)
                    {
                        sDescription = dgTrans[iCol, iRow].Value.ToString();
                    }

                    else //iCol == 3
                    {
                        sRetailPrice = dgTrans[iCol, iRow].Value.ToString();
                    }                
                }                
                daShop.UpdateCommand = cnShop.CreateCommand();

                daShop.UpdateCommand.CommandText = "UPDATE Transactions "
                                                 + "SET ClientID='" + sClientID + "', TransactionDate='" + sTransDate + "' "
                                                 + "WHERE TransactionNumber='" + iRow + "' ";

                daShop.UpdateCommand.Parameters.Add("ClientID", OleDbType.Char, 0, "ClientID");
                daShop.UpdateCommand.Parameters.Add("TransactionDate", OleDbType.Char, 0, "TransactionDate");
                daShop.Update(dstShop, "Transactions");
            }
        } 
Sloppy I know, but right now I'm just desperate to get it to save.
If I weren't insane: I couldn't be so brilliant! - The Joker
User avatar
Ron2K
Forum Technical Administrator
Posts: 9050
Joined: 04 Jul 2006, 16:45
Location: Upper Hutt, New Zealand
Contact:

Re: Updating tables while Inner Joined

Post by Ron2K »

Please post the SQL statement that contains the INNER JOIN (I only saw one statement in your code, and it doesn't have a join), as well as your database schema. That will give me something to work with.
Kia kaha, Kia māia, Kia manawanui.
Bladerunner
Registered User
Posts: 14338
Joined: 04 Sep 2004, 02:00
Processor: i386DX Sooper
Motherboard: A blue one
Graphics card: A red one
Memory: Hard drive
Location: On a Möbius strip
Contact:

Re: Updating tables while Inner Joined

Post by Bladerunner »

Ron2K wrote:Please post the SQL statement that contains the INNER JOIN (I only saw one statement in your code, and it doesn't have a join), as well as your database schema. That will give me something to work with.

Code: Select all

SELECT        Transactions.TransactionNumber, Transactions.TransactionDate, Transactions.ClientID, Items.Description, Items.RetailPrice
FROM            (Transactions INNER JOIN Items ON Transactions.ItemID = Items.ItemID)
ImageImage
If I weren't insane: I couldn't be so brilliant! - The Joker
Bladerunner
Registered User
Posts: 14338
Joined: 04 Sep 2004, 02:00
Processor: i386DX Sooper
Motherboard: A blue one
Graphics card: A red one
Memory: Hard drive
Location: On a Möbius strip
Contact:

Re: Updating tables while Inner Joined

Post by Bladerunner »

If this will be of any help as well, this is the custom table:

ImageImage
If I weren't insane: I couldn't be so brilliant! - The Joker
doo_much
Registered User
Posts: 26022
Joined: 13 May 2004, 02:00
Location: Getting there...
Contact:

Re: Updating tables while Inner Joined

Post by doo_much »

Try this

Code: Select all

        private void toolBtnSaveTrans_Click(object sender, EventArgs e)   //Custom Save
        {
            string sTransDate = "", sClientID = "", sDescription = "", sRetailPrice = "";
            bsTrans.EndEdit();

            for (int iRow = 0; iRow <= dgTrans.RowCount - 2; iRow++)
            {
                for (int iCol = 0; iCol <= dgTrans.ColumnCount - 1; iCol++)
                {                   
                    if (iCol == 0)
                    {
                        sTransDate = dgTrans[iCol, iRow].Value.ToString();
                    }

                    else if (iCol == 1)
                    {
                        sClientID = dgTrans[iCol, iRow].Value.ToString();
                    }

                    else if (iCol == 2)
                    {
                        sDescription = dgTrans[iCol, iRow].Value.ToString();
                    }

                    else //iCol == 3
                    {
                        sRetailPrice = dgTrans[iCol, iRow].Value.ToString();
                    }                
                }                
                daShop.UpdateCommand = cnShop.CreateCommand();

//                daShop.UpdateCommand.CommandText = "UPDATE Transactions "
//                                                 + "SET ClientID='" + sClientID + "', TransactionDate='" + sTransDate + "' "
//                                                 + "WHERE TransactionNumber='" + iRow + "' ";
//
                   daShop.UpdateCommand.CommandText = "UPDATE Transactions"
                                                    + "INNER JOIN Items  ON Transactions.ItemID = Items.ItemID"
                                                    + "SET ClientID='" + sClientID + "', TransactionDate='" + sTransDate + "' "
                                                    + "WHERE TransactionNumber='" + iRow + "' ";

                daShop.UpdateCommand.Parameters.Add("ClientID", OleDbType.Char, 0, "ClientID");
                daShop.UpdateCommand.Parameters.Add("TransactionDate", OleDbType.Char, 0, "TransactionDate");
                daShop.Update(dstShop, "Transactions");
            }
        } 
Sloppy I know, but I can't program worth a damn!
MOOD - Thirsty

A surprising amount of modern pseudoscience is coming out of the environmental sector. Perhaps it should not be so surprising given that environmentalism is political rather than scientific.
Timothy Casey
Bladerunner
Registered User
Posts: 14338
Joined: 04 Sep 2004, 02:00
Processor: i386DX Sooper
Motherboard: A blue one
Graphics card: A red one
Memory: Hard drive
Location: On a Möbius strip
Contact:

Re: Updating tables while Inner Joined

Post by Bladerunner »

doo_much wrote:Try this

Code: Select all

code
Sloppy I know, but I can't program worth a damn!
Thanks for the reply. The program still runs normally, and I know the for-loops work, but for some reason the data isn't updated. I think the SQL is probably okay now, but the update method is still giving me problems.
If I weren't insane: I couldn't be so brilliant! - The Joker
Post Reply