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@teg 1K@m3r1ka" ;
SqlConnection conn = new SqlConnection(con);
string fetch = string.Format("Insert Into questions(QID, question) values ('{0}', '{1}')",qid.Trim(),txtQues t.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.
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@teg
SqlConnection conn = new SqlConnection(con);
string fetch = string.Format("Insert Into questions(QID, question) values ('{0}', '{1}')",qid.Trim(),txtQues
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!!
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.Select
on the second page, you can retrieve this value into a variable for your save routine:
string StrClientID = Session("OrgID");