OK
Making some progress. I can now get the database to update, but it will either just pass the 1st select value for each selected line if I use:
addSubCats.InsertParameters["LOOKUP_TYPE_ID"].DefaultValue = SUB_CATEGORY.SelectedValue.ToString();
and will put all entries on 1 line (but inserts multiple rows) if I use
addSubCats.InsertParameters["LOOKUP_TYPE_ID"].DefaultValue = Request.Form["SUB_CATEGORY"].ToString();
Any ideas on how I can get it to put the correct values in?
________________________________________________________________________
Hi.
I'm trying to insert values (sometimes single, sometimes multiple) from a ListBox on a webform to a SQL database. I need to insert a new line for each entry and have the following code, set in a code behind file that fires when the user clicks on Insert button:
protected void AddCatButton_Click(object sender, EventArgs e)
{
foreach (ListItem item in SUB_CATEGORY.Items)
if (item.Selected)
{
addSubCats.InsertParameters["COMMUNICATION_ID"].DefaultValue = Request.QueryString["COMMUNICATION_ID"].ToString();
addSubCats.InsertParameters["LOOKUP_TYPE_ID"].DefaultValue = SUB_CATEGORY.SelectedValue.ToString();
addSubCats.Insert();
}
Response.Redirect("viewcase.aspx?SOURCE_REFERENCE=" + Request.QueryString["SOURCE_REFERENCE"] + "&SUBJECT_REFERENCE=" + Request.QueryString["SUBJECT_REFERENCE"] + "&COMMUNICATION_ID=" + Request.QueryString["COMMUNICATION_ID"]);
}
However, as ever with the most simple things, it's not working.
If I remove the foreach state and the if statements, it will insert the records to the database, but lists the multiple values in the field and in 1 row, not multiple rows as I need it too.
Any ideas?
Cheers
Codemagpie