SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Inserting Comma Seperated Values in Sql Server 2005


Inserting Comma Seperated Values in Sql Server 2005

Author
Message
Aswanth
Aswanth
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 214
I'm Using Asp.Net with C#..

i'm having One ListBox control in which I'm getting Data Dynamically.. I want to Insert the Selected data (or ALL DATA) from ListBox Control into My Table(Get_Data) in Sql Server Database.. Here I'm displaying NAMES(EMP_Names) in LISTBOX Control.. I want to Insert there ID(EMP_ID) values instead of NAMES..

EVEN some times MULTIPLE SELECTIONS will also been done in LISTBOX Control.. I want to INSERT those MULTIPLE values in ONE COLUMN as COMMA SEPERATED VALUES (ex:1,2,3,4,5,6,7----)..

How to do this..

Please give me the code..


Thank You..
WayneS
WayneS
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10074 Visits: 10574
Aswanth (5/29/2008)
I'm Using Asp.Net with C#..

i'm having One ListBox control in which I'm getting Data Dynamically.. I want to Insert the Selected data (or ALL DATA) from ListBox Control into My Table(Get_Data) in Sql Server Database.. Here I'm displaying NAMES(EMP_Names) in LISTBOX Control.. I want to Insert there ID(EMP_ID) values instead of NAMES..

EVEN some times MULTIPLE SELECTIONS will also been done in LISTBOX Control.. I want to INSERT those MULTIPLE values in ONE COLUMN as COMMA SEPERATED VALUES (ex:1,2,3,4,5,6,7----)..

How to do this..

Please give me the code..


Thank You..


I think this article may help you out.
http://www.sqlservercentral.com/articles/TSQL/62867/

Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings

SoCal_DBD
SoCal_DBD
SSChasing Mays
SSChasing Mays (601 reputation)SSChasing Mays (601 reputation)SSChasing Mays (601 reputation)SSChasing Mays (601 reputation)SSChasing Mays (601 reputation)SSChasing Mays (601 reputation)SSChasing Mays (601 reputation)SSChasing Mays (601 reputation)

Group: General Forum Members
Points: 601 Visits: 1528
I'm not sure if I'm understanding you problem correctly, but just iterate throught the items in the ListBox, building a string as you go and then pass that to a stored procedure that accepts that string as a variable and inserts it into the table. If you must store the string as a comma separated value, then I would do this in your .NET application:


protected void btnSaveSelection_Click(object sender, EventArgs e)
{
// Get the corresponding ids for the selected names
string ids = string.Empty;

for (int i = 0; i < lstNames.Items.Count; i++)
{
// If the name was selected, store in variable
if (lstNames.Items[i].Selected)
{
ids += (ids == string.Empty) ? lstNames.Items[i].Value : "," + lstNames.Items[i].Value;
}
}

// Call stored procedure to insert the concatenated string
clsDB db = new clsDB();
db.SaveSelectedNames(ids);
}



clsDB is your database class that contains a call to the stored procedure, passing the string of ids. This is just the 10,000 foot perspective. Obviously, you would include some error handling, but you get the idea. Not sure if this is what you're looking for??
bmaheswararaoc
bmaheswararaoc
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 1
Ho to Fetch the same values from the DB please provide code ....
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search