May 29, 2008 at 2:25 am
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..
May 29, 2008 at 7:08 am
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
May 30, 2008 at 11:02 am
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.Selected)
{
ids += (ids == string.Empty) ? lstNames.Items.Value : "," + lstNames.Items.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??
October 28, 2012 at 11:26 pm
Ho to Fetch the same values from the DB please provide code ....
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply