Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to insert a record into one table

return the id so that i can insert the new id into a many=many table.

for some reason, i am inserting the records, but the id isn't being returned for the insert into the many to many table.

i can't figure any logical reason the returns aren't coming back. there's a bit more code that goes with theis. there's the sql sprocs and the dals used by the blls. if needed, and it probably is, i'd be more than happy to put those into the post...i just didn't want to paste in a crazy wall of text.

many thanks

codebehind
C#
protected void inputVarBTN_Click(object sender, EventArgs e)
{
    variableBO vBO = new variableBO();
    locationsBO loBO = new locationsBO();
    variablesBLL vBLL = new variablesBLL();
    locationsBLL loBLL = new locationsBLL();

    int loResult = 0;
    int vResult = 0;

    vBO.variableName = varInputTB.Text;
    loBO.excelPageID = int.Parse(varExcpageDDL.SelectedValue);
    loBO.col = varInputColTB.Text;
    loBO.row = int.Parse(varInputRowTB.Text);
    loBO.concatLoc = varExcpageDDL.SelectedItem.Text + varInputColTB.Text + varInputRowTB.Text;
    vBO.boID = int.Parse(varInputvbObjectDDL.SelectedValue);
    vBO.description = varInputDescriptionTB.Text;

    try
        {
            //returns locationID
            loResult = loBLL.insert(loBO);

            if (loResult > 0)
            {
                //locationID becomes the locationid for the variablebo
                vBO.locationID = loResult;
                try
                {
                    //returns variableID
                    vResult = vBLL.insert(vBO);

                    if(vResult > 0)
                    {
                        try
                        {
                            equivLocationBO eqLocBO = new equivLocationBO();
                            equivLocationBLL eqLocBLL = new equivLocationBLL();
                            eqLocBO.locationID1 = vResult;
                            foreach (ListItem li in varInputEqLocDDCB.Items)
                            {
                                if (li.Selected)
                                {
                                    eqLocBO.locationID2 = int.Parse(li.Value);
                                    eqLocBLL.insert(eqLocBO);
                                }
                            }
                            inputVLabel.Text = "Insert New variable Successful.";
                        }
                        catch (Exception eee)
                        {
                            inputVLabel.Text = eee.Message.ToString();
                        }
                        finally
                        {
                            vBLL = null;
                            vBO = null;
                        }
                    }
                    else
                    {
                        inputVLabel.Text = "Insert new Variable Failed.";
                    }
                }
                catch(Exception eee)
                {
                    inputVLabel.Text = eee.Message.ToString();
                }
                finally
                {
                    vBLL = null;
                    vBO = null;
                }
            }
            else
            {
                inputLLabel.Text = "Insert New Location Failed.";
            }
        }
        catch (Exception ee)
        {
            inputLLabel.Text = ee.Message.ToString();
        }
        finally
        {
            loBO = null;
            loBLL = null;
        }
    }
Posted
Comments
khurram ali lashari 7-Feb-14 14:10pm    
You Want to return Inserted Record Id From DataBase to Insert many to many Table ??
Would You Please Explain Little Bit more...:D
What is your meaning many to many ? are You talking about Bridge Table.?
[no name] 9-Feb-14 13:11pm    
He means to say, he wanna insert into multiple tables

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900