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.
Author |
Topic |
alxtech
Yak Posting Veteran
66 Posts |
Posted - 2005-12-22 : 11:04:27
|
I am trying to insert two or more selected options from a list box (server control) into an SQL 2000 database, currently it only inserts one option even if more are selected. I am using Visual Studio .NET.Thank you for your help. |
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2005-12-22 : 11:43:01
|
U can do it as :the easy, but less efficient way1. Create each insert statement seperately and execute in a loopor the much elegent way2. Write a stored proc to accept the list of data to be inserted as paarameter and insert in a loop inside stored procedure |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-23 : 00:58:07
|
It is better to handle at Front End by using the suggested method 1MadhivananFailing to plan is Planning to fail |
 |
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2005-12-23 : 08:46:04
|
Madhi,Isn't it more time consuming to connect to Server over & over? |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-23 : 09:04:07
|
quote: Originally posted by Srinika Madhi,Isn't it more time consuming to connect to Server over & over?
Why? Have a connection and using loop insert records and close the connection at the endMadhivananFailing to plan is Planning to fail |
 |
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2005-12-23 : 09:23:38
|
Say, if u need to insert 25 records:1. Until each Insert Statement is sent to the server, u have to keep the connection opened.2. The Complete String is passed to the Server side each time needed3. The messages are moved back & forth (from / to --> client / server)4. Each Insert Statement has to be compiled for SQL server (client passes a string) , whereas, the Stored proc is pre compiled. |
 |
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2005-12-23 : 10:21:31
|
Option 1 is preferable.Interfaces need to send clean data to the server. Sending concatenated string parameters that need to be parsed is just asking for trouble.And your interface should not be sending insert statements anyway. It should be calling a stored procedure (compiled) to insert each record. |
 |
|
|
|
|