TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Marieee
NA
12
2.7k
Select multiple values from listbox and insert in SQL db
Feb 25 2017 1:44 PM
Hi!
I'm working on an ASP.NET website in C#. The idea is to insert data into a SQL Server database through the website. I wrote a stored procedure for insert data and code in C#. The data from Table 3 is inserting through Listbox, but as a string, not as foreign key. I think that is a bad way because of searching data.
Does anyone have an idea hot to insert ID from Table 3 in Table 1, through Listbox, if I select multiple text values from that table?
Fields in Table 3: ID, col5.
This is stored procedure.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[TEST]
// Table1
@col1 NVARCHAR(MAX),
@col2 NVARCHAR(MAX),
@col3 NVARCHAR(MAX),
@col4 NVARCHAR(MAX),
// Table 2
@FileName NVARCHAR(50),
@FilePath NVARCHAR(200),
// Table 3
@col4 NVARCHAR(MAX)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Table_Var TABLE (ID1 INT)
INSERT INTO Table1 (col1,col2,col3,col4,COL5)
OUTPUT inserted.ID1
INTO @Table_Var(ID1)
SELECT @col1,@col2,@col3,@col4, @COL5
INSERT INTO Table2 (colID,FileName,FilePath)
SELECT ID1,@FileName,@FilePath
FROM @Table_Var
END
This is part of code that is inserting text value from Table 3, through Listbox and Label.
foreach (ListItem item in Table3.Items)
{
if (item.Selected)
{
try
{
Label1.Text = item.Text + ", " + Label1.Text;
cmd.Parameters["@COL5"].Value = Label1.Text;
}
catch (Exception ex)
{
}
}
}
Reply
Answers (
1
)
How to display data between two dates in asp.net C#
Using MS SQL with ASP.Net core project