Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Replication (2012)
 multiple insert listbox(all items),dropdownlist

Author  Topic 

jiyan
Starting Member

1 Post

Posted - 2013-05-05 : 05:15:13
Is it possible to insert multiple records using listbox(all items),dropdownlist(selected value).

I have a table enrolnment that will be storing student history for any given academic year. The fields are; Studentid,academicyear,grade. studentid is bound to listbox, the other fields are bound to dropdownlist. the table is already prepopulated with prior years data.

Since the table will be keeping history hence there is no need for primary key.
for example the table has the following data;
studentid academicyear grade
1 2012 3
2 2012 3
3 2012 3
4 2012 3
5 2012 3
in a new academic year new records should be inserted like
studentid academicyear grade
1 2013 4
2 2013 4
3 2013 4
4 2013 4
5 2013 4
is this possible at a click of a button given all items in list box(studentid) and selected academicyear from dropdownlist.

Thanks

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-05-05 : 21:12:14
quote:
Since the table will be keeping history hence there is no need for primary key.
Except in very rare cases, it is always better to have a primary key. If there are no single candidate keys, you could use a composite key or surrogate key.

That aside, to answer your question about sending multiple rows to the database - yes it can be done. What you would need to do is to extract the data that contains the selected items, pack it up and send it to the server, write code on the server to process that data.

There are multiple ways to do it. One would be to create a table-valued parameter and send that to the server - see here: http://msdn.microsoft.com/en-us/library/bb675163.aspx

Other ways would be to construct an XML fragement and send that to the server, or send comma-separated values etc.
Go to Top of Page
   

- Advertisement -