# Asp.net, c#, listbox

**URL:** https://forum.kirupa.com/t/asp-net-c-listbox/223981
**Category:** Uncategorized
**Created:** [April 27, 2007, 8:40am UTC](https://forum.kirupa.com/t/asp-net-c-listbox/223981 "2007-04-27T08:40:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ctzack](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ctzack/32/3561_2.png) [@ctzack](https://forum.kirupa.com/u/ctzack)
#### Post date: [April 27, 2007, 8:40am UTC](https://forum.kirupa.com/t/asp-net-c-listbox/223981/1 "2007-04-27T08:40:09Z")

</div>

hi there.  
i’m a new member here n i’m a beginner in [asp.net](http://asp.net) - C#  
i have a problem here, i hope sumbody out there can help me to solve this prob.

here’s my prob :  
i have few other textboxes for user to insert datas, and a listbox for the user to select multiple item on my page which loads a list of empname from empa table.  
here’s my code to load the list in the listbox :

[SIZE=2]dbEmp.Open();  
cmd = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080]SqlCommand[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#800000]"Select empno, empname "[/COLOR][/SIZE][SIZE=2] +  
[/SIZE][SIZE=2][COLOR=#800000]“from empa order by empname”[/COLOR][/SIZE][SIZE=2], dbEmp);  
dr = cmd.ExecuteReader();  
lstEmp.DataSource = dr;  
lstEmp.DataValueField = [/SIZE][SIZE=2][COLOR=#800000]“empno”[/COLOR][/SIZE][SIZE=2];  
lstEmp.DataTextField = [/SIZE][SIZE=2][COLOR=#800000]“empname”[/COLOR][/SIZE][SIZE=2];  
lstEmp.DataBind();  
cmd = [/SIZE][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][SIZE=2];  
dbEmp.Close();  
[/SIZE]  
i am not sure how to write the code for the listbox item in order to insert the item selected by user into sql.

right now i am stuck, this is my code to insert into d db :  
[SIZE=2]dbEmp.Open();  
cmd = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080]SqlCommand[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#800000]“Create\_Memo”[/COLOR][/SIZE][SIZE=2], dbEmp);  
cmd.CommandType = [/SIZE][SIZE=2][COLOR=#008080]CommandType[/COLOR][/SIZE][SIZE=2].StoredProcedure;  
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]“pempno1”[/COLOR][/SIZE][SIZE=2], lstEmp.Items[1].Value);  
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]“pempno2”[/COLOR][/SIZE][SIZE=2], lstEmp.Items[2].Value);  
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]“pempno3”[/COLOR][/SIZE][SIZE=2], lstEmp.Items[3].Value);  
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]“pempno4”[/COLOR][/SIZE][SIZE=2], lstEmp.Items[4].Value);  
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]“pempno5”[/COLOR][/SIZE][SIZE=2], lstEmp.Items[5].Value);  
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]“pempno6”[/COLOR][/SIZE][SIZE=2], lstEmp.Items[6].Value);  
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]“pempno7”[/COLOR][/SIZE][SIZE=2], lstEmp.Items[7].Value);  
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]“pempno8”[/COLOR][/SIZE][SIZE=2], lstEmp.Items[8].Value);  
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]“pempno9”[/COLOR][/SIZE][SIZE=2], lstEmp.Items[9].Value);  
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]“pempno10”[/COLOR][/SIZE][SIZE=2], lstEmp.Items[10].Value);  
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]“ppriorityid”[/COLOR][/SIZE][SIZE=2], ddlPrio.SelectedValue);  
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]“pmemodate”[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#008080]DateTime[/COLOR][/SIZE][SIZE=2].Today.ToShortDateString());  
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]“pmemotitle”[/COLOR][/SIZE][SIZE=2], txtTitle.Text);  
cmd.Parameters.AddWithValue([/SIZE][SIZE=2][COLOR=#800000]“pmemocontent”[/COLOR][/SIZE][SIZE=2], txtContent.Text);  
cmd.ExecuteNonQuery();  
dbEmp.Close();  
Response.Redirect([/SIZE][SIZE=2][COLOR=#800000]“previewMemo.aspx”[/COLOR][/SIZE][SIZE=2]);  
[/SIZE]  
fyi, i use store proc to insert data into d particualr table.  
here is my stored proc :

[SIZE=2][COLOR=#0000ff]create[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]proc[/COLOR][/SIZE][SIZE=2] Create\_Memo  
@pempno1 [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2]COLOR=#808080,  
[/COLOR][/SIZE][SIZE=2]@pempno2 [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2]COLOR=#808080,  
[/COLOR][/SIZE][SIZE=2]@pempno3 [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2]COLOR=#808080,  
[/COLOR][/SIZE][SIZE=2]@pempno4 [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2]COLOR=#808080,  
[/COLOR][/SIZE][SIZE=2]@pempno5 [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2]COLOR=#808080,  
[/COLOR][/SIZE][SIZE=2]@pempno6 [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2]COLOR=#808080,  
[/COLOR][/SIZE][SIZE=2]@pempno7 [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2]COLOR=#808080,  
[/COLOR][/SIZE][SIZE=2]@pempno8 [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2]COLOR=#808080,  
[/COLOR][/SIZE][SIZE=2]@pempno9 [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2]COLOR=#808080,  
[/COLOR][/SIZE][SIZE=2]@pempno10 [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2]COLOR=#808080,  
[/COLOR][/SIZE][SIZE=2]@pPriorityID [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2]COLOR=#808080,  
[/COLOR][/SIZE][SIZE=2]@pMemoDate [/SIZE][SIZE=2][COLOR=#0000ff]smalldatetime[/COLOR][/SIZE][SIZE=2][COLOR=#808080],  
[/COLOR][/SIZE][SIZE=2]@pMemoTitle [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2]COLOR=#808080,[/COLOR][/SIZE][SIZE=2]  
@pMemoContent [/SIZE][SIZE=2][COLOR=#0000ff]varchar[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2]COLOR=#808080  
[/COLOR][/SIZE][SIZE=2]  
[/SIZE][SIZE=2][COLOR=#0000ff]as  
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]insert[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]into[/COLOR][/SIZE][SIZE=2] memo [/SIZE][SIZE=2][COLOR=#808080]([/COLOR][/SIZE][SIZE=2]empno1[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] empno2[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] empno3[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] empno4[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] empno5[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] empno6[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] empno7[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] empno8[/SIZE][SIZE=2][COLOR=#808080],  
[/COLOR][/SIZE][SIZE=2]empno9[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] empno10[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] PriorityID[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] MemoDate[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] MemoTitle[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] MemoContent[/SIZE][SIZE=2][COLOR=#808080])  
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]values[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#808080]([/COLOR][/SIZE][SIZE=2]@pempno1[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] @pempno2[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] @pempno3[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] @pempno4[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] @pempno5[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] @pempno6[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] @pempno7[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] @pempno8[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] @pempno9[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] @pempno10[/SIZE][SIZE=2][COLOR=#808080],  
[/COLOR][/SIZE][SIZE=2]@pPriorityID[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] @pmemodate[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] @pMemoTitle[/SIZE][SIZE=2][COLOR=#808080],[/COLOR][/SIZE][SIZE=2] @pMemoContent[/SIZE][SIZE=2][COLOR=#808080])  
[/COLOR][/SIZE][SIZE=2]  
[/SIZE]  
i hope sumbody can help me. tq in advance.
