Link to home
Start Free TrialLog in
Avatar of siddhuoops
siddhuoops

asked on

Insert statement and dropdownlist

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.
Avatar of samtran0331
samtran0331
Flag of United States of America image

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.
ASKER CERTIFIED SOLUTION
Avatar of samtran0331
samtran0331
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of siddhuoops
siddhuoops

ASKER

Thanks!!