Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Inserting Comma Seperated Values in Sql Server 2005 Expand / Collapse
Author
Message
Posted Thursday, May 29, 2008 2:25 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, October 15, 2008 12:29 AM
Points: 30, 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..
Post #508240
Posted Thursday, May 29, 2008 7:08 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, July 24, 2014 7:55 PM
Points: 6,582, Visits: 8,860
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
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
Post #508360
Posted Friday, May 30, 2008 11:02 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, July 25, 2014 3:18 PM
Points: 161, Visits: 867
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??

Post #509264
Posted Sunday, October 28, 2012 11:25 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, October 29, 2012 8:01 AM
Points: 1, Visits: 1
Ho to Fetch the same values from the DB please provide code ....
Post #1378105
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse