We help IT Professionals succeed at work.

Insert statement and dropdownlist

238 Views
Last Modified: 2008-02-01
Hi there,

            I have to do some inserting in my database but I am running into a problem. I have a table called questions(qid, organization_ID, questions). In my login.aspx, I have a dropdownlist of clients where they select a client and then go to a next page where I have a textbox to add a question. Now with sql Insert statement, I will be able to add a question but how would I be able to add the client they selected in login.aspx page? This is what I have done to add the question.

private void Add(string qid)
    {
        string con = "Data Source=sasql01;Initial Catalog=sandbox; Persist Security Info=True;User ID=sa_sql;Password=str@teg1K@m3r1ka";
        SqlConnection conn = new SqlConnection(con);
        string fetch = string.Format("Insert Into questions(QID, question) values ('{0}', '{1}')",qid.Trim(),txtQuest.Text);
        SqlCommand cmd = new SqlCommand(fetch, conn);
        conn.Open();
        try
        {
            cmd.ExecuteNonQuery();
        }
        catch(SqlException ex)
        {
            Response.Write(ex.ToString());
            return;
        }
       
        conn.Close();
    }

But I have no idea on how to add the organization_ID into the question table.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007

Commented:
there are a few ways you can pass that value to the second page, one way is to use a session variable...

on your first page, when the user clicks the button to go to the second page,
save the dropdownlist value to session:
Session("OrgID") = DropDownListClients.SelectedValue;

on the second page, you can retrieve this value into a variable for your save routine:
string StrClientID = Session("OrgID");
You may want to pass the selected organization_ID from the login.aspx to the page where you save using a querystring variable or save it in session variable and retrieve and then save it.
CERTIFIED EXPERT
Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks!!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.