Home SQL Subquery returned more than 1 value when adding Procedure
Reply: 0

SQL Subquery returned more than 1 value when adding Procedure

user1909
1#
user1909 Published in June 19, 2018, 6:17 pm

I tried creating procedure in SQL Server so that I can pass the users_id value to another table.

However, when filling in data asp.net returns an error that subquery returned more than 1 value. Here is my procedure:

CREATE PROCEDURE [dbo].[insert_rent]
    @comment_info NVARCHAR(MAX),
    @booth_size NVARCHAR(MAX),
    @customer_type NVARCHAR(MAX),
    @booth_type NVARCHAR(MAX),
    @customer_email TEXT,
    @customer_mobile TEXT
AS
    DECLARE @Users_Id INT 

    IF EXISTS (SELECT Id FROM Users)
    BEGIN
        SET @Users_Id = (SELECT Id FROM Users)

        INSERT INTO Rent (rent_comments, booth_size, customer_type, booth_type, customer_email, customer_mobile, Users_id) 
        VALUES (@comment_info, @booth_size, @customer_type, @booth_type, @customer_email, @customer_mobile, @Users_Id)
    END

Here is my code:

String CS = ConfigurationManager.ConnectionStrings["BoothsConnectionString1"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
    SqlCommand cmd = new SqlCommand("insert_rent", con);
    cmd.CommandType = CommandType.StoredProcedure;

    con.Open();
    cmd.Parameters.Add("@comment_info", SqlDbType.NVarChar).Value = comment_input.Text;
    cmd.Parameters.Add("@booth_size", SqlDbType.NVarChar).Value = size_dropwdown.SelectedValue.ToString();
    cmd.Parameters.Add("@customer_type", SqlDbType.NVarChar).Value = customer_type_dropdown.SelectedValue.ToString();
    cmd.Parameters.Add("@booth_type", SqlDbType.NVarChar).Value = booth_type_dropdown.SelectedValue.ToString();
    cmd.Parameters.Add("@customer_email", SqlDbType.NVarChar).Value = customer_email.Value;
    cmd.Parameters.Add("@customer_mobile", SqlDbType.NText).Value = customer_mobilenumber.Value;

    cmd.ExecuteNonQuery();

I'm fairly sure there is something wrong with my procedure.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.342935 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO