locked
getting error in stored procedure,email required RRS feed

  • Question

  • User-1458744719 posted

    function calling stored procedure

    Public Shared Function AddImageToScrapBook(ByVal con As SqlConnection, ByVal trans As SqlTransaction, ByVal ImageName As String, ByVal ScrapBookId As String) As Integer
    Dim ClientEmail As String = HttpContext.Current.Session("ClientEmailId")

    Using cmd As New SqlCommand("dbo.AddImageToScrapBook", con)

    cmd.CommandType = CommandType.StoredProcedure

    cmd.Parameters.Add("@ScrapBookId", SqlDbType.NVarChar).Value = ScrapBookId
    cmd.Parameters.Add("@ImageName", SqlDbType.NVarChar, 100).Value = ImageName
    cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 150).Value = ClientEmail
    cmd.Parameters.Add("ReturnValue", SqlDbType.Int).Direction = ParameterDirection.ReturnValue


    If trans IsNot Nothing Then
    cmd.Transaction = trans
    End If

    cmd.ExecuteNonQuery()
    con.Close()
    Return Convert.ToInt32(cmd.Parameters("ReturnValue").Value)
    End Using
    End Function

    stored procedure:


    Create PROCEDURE [dbo].[AddImageToScrapBook]

    (
    @ScrapBookId nvarchar (Max),
    @ImageName nvarchar (100) ,
    @Email nvarchar (150)
    )
    AS
    BEGIN
    SET NOCOUNT ON
    INSERT INTO [dbo].[ScrapBookImages] ([ScrapBookId],
    [ImageName] ,[Email]) VALUES (@ScrapBookId, @ImageName,@Email )

    RETURN 1
    END

    GO

    ERROR :Procedure or function 'AddImageToScrapBook' expects parameter '@Email', which was not supplied.

    I want if  user login den we have email else we dont have ........how can i make email field optional or allow to enter NULL values.

    Monday, May 20, 2013 6:43 AM

Answers

  • User-1225287840 posted
    Just modify your sp as below,
    Create PROCEDURE [dbo].[AddImageToScrapBook]
    
    (
    @ScrapBookId nvarchar (Max),
    @ImageName nvarchar (100) ,
    @Email nvarchar (150) = NULL
    )
    AS
    .......
    

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 20, 2013 6:54 AM

All replies

  • User-1225287840 posted
    Just modify your sp as below,
    Create PROCEDURE [dbo].[AddImageToScrapBook]
    
    (
    @ScrapBookId nvarchar (Max),
    @ImageName nvarchar (100) ,
    @Email nvarchar (150) = NULL
    )
    AS
    .......
    

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 20, 2013 6:54 AM
  • User-1716253493 posted
    if Session("ClientEmailId") isnot nothing then... i think session issue
    Monday, May 20, 2013 7:05 AM
  • User-1011137159 posted

    Here one of the things which I can see is

    Create PROCEDURE[dbo].[AddImageToScrapBook]
    (
    @ScrapBookId nvarchar (Max),
    @ImageName nvarchar (100) ,
    @Email nvarchar (150) ,
    @ReturnValue nvarchar(200) output
    )


    Monday, May 20, 2013 7:12 AM