Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a 3-tier architecture...trying to insert something with checkboxlist...

would this bit of code even work? every time i try to insert...i get a fail.

C#
protected void submitButton_Click(object sender, EventArgs e)
{
    //Lets validate the page first
    if (!Page.IsValid)
        return;

    int intResult = 0;
    // Page is valid, lets go ahead and insert records
    // Instantiate BAL object
    sBLL scBLL = new sBLL();
    // Instantiate the object we have to deal with
    sBO scBO = new sBO();
    // set the properties of the object
    sDAL scdal = new sDAL();

    scBO.scholarshipName = scNameText.Text;
    scBO.orgID = 1;


    try
    {
        intResult = scBLL.Insert(scBO);
        if (intResult > 0)
            lblMessage.Text = "New record inserted successfully.";
        else
            lblMessage.Text = "failed";

    }
    catch (Exception ee)
    {
        lblMessage.Text = ee.Message.ToString();
    }
    finally
    {
        int sID = scBO.sID;
        foreach (ListItem li in CheckBoxList1.Items)
        {
            if (li.Selected)
            {
                mascidBLL masciBLL = new mascidBLL();
                mascidBO masciBO = new mascidBO();
                masciBO.sID = sID;
                masciBO.majorID = int.Parse(li.Value);
            }
        }
    }


        scBO = null;
        scBLL = null;
    }


i have a bll, bo and a dal if that helps.

thanks in advance
Posted
Updated 8-May-13 18:08pm
v2

1 solution

You never added or inserted anything. Take a look: all controls have some parent. To insert anything, you should first create a new object. This means a call to one (exactly one) constructor. Next step, you need to establish a parent-child relation between parent and a new element. So, you need one constructor call and one Insert/Add call.

As you though you were close, I trust I can leave the rest to you. Especially in case you did not really tell us an exact type of the ListItem or CheckBoxList classes. Did you know that there are more then one UI library in .NET. Even though I can guess what is it, I think guesswork is not an appropriate thing to do here. You ask a question, you specify all which is relevant to you question, OK? In particular, you should tag UI library or application type.

Now, let's see if you can complete the solution of the problem.

Well, also, it's not clear why do you call it "batch" and how it this related to "update" (of what). If you have some follow-up questions, I hope you explain everything the way leaving no ambiguity.

Good luck,
—SA
 
Share this answer
 
Comments
[no name] 9-May-13 0:03am    
honestly, you couldn't have been anymore unhelpful or rude.

yesterday i asked a question and posted all the code i could and got complaints about posting "TOO MUCH CODE" some of you prima donnas need to chill. i said THINK i'm close. if you simply asked for more code, i'd have happily provided it.
Sergey Alexandrovich Kryukov 9-May-13 0:18am    
Too bad, for you. You are not collaborative. No more help, sorry.
—SA
[no name] 9-May-13 1:14am    
you weren't any help so it's really no loss. please stay out of this wuestion if you're going to be a jerk.

THAT is how you could be helpful.
Sergey Alexandrovich Kryukov 9-May-13 1:18am    
As to "stay out", sorry, no way. I'll have to consider your behavior as unacceptable, to make you a candidate for cancellation of your account. These comments are a bit too much. We don't tolerate rude/offensive behavior.
—SA
[no name] 9-May-13 1:22am    
rude offensive behavior? check your posts
i'm trying to ask a question adn get some help and you came onto my question acting like a complete dbag and then proceeded to block my question from being answered.

just because you think you know some code doesnt give you the right to act like a jerk to new coders trying to get some help. you could have asked for more code to see the problem. instead you acted like a jerk.

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