none
SqlParameter Was not supplied RRS feed

  • Question

  • I get an error that the SqlParameter "Revision" was not supplied. Could you assist me with what the error is talking about?


    sqlResult = 0;
    sqlCommand = @"Insert INTO dbo.ControlObjects (INSTALLATION, Revision, OBJNAM, [Key], Value, Deleted, ParamType)" +
                  "VALUES (@INSTALLATION, @Revision, @OBJNAM, @Key, @Value, @Deleted, @ParamType)";
    
    sqlResult = this.Database.ExecuteSqlCommand(sqlCommand, 
                                                new SqlParameter("@INSTALLATION", installationId),
                                                new SqlParameter("@Revision", 0L), 
                                                new SqlParameter("@OBJNAM", objName),
                                                new SqlParameter("@Key", key),
                                                new SqlParameter("@Value", value),
                                                new SqlParameter("@Deleted", false), 
                                                new SqlParameter("@ParamType", "Saved")); 

      


    pianoboyCoder


    Thursday, January 11, 2018 6:15 AM

All replies

  • I am getting an error below. The error says invalid syntax by 'Key' . I do not see the issue. Can somebody tell me what I am doing wrong.

      string sqlCommand = @"Select * From dbo.ControlObjects where INSTALLATION = @INSTALLATION And OBJNAM = @OBJNAM And Key = @Key ";
                sqlResult = this.Database.ExecuteSqlCommand(sqlCommand, 
                                                            new SqlParameter("@INSTALLATION", installationId), 
                                                            new SqlParameter("@OBJNAM", objName), 
                                                            new SqlParameter("@Key", key));



    pianoboyCoder

    Thursday, January 11, 2018 12:06 AM
  • Try [key] for [Key] = @key as per it's a reserved keyword

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites









    Thursday, January 11, 2018 12:30 AM
    Moderator
  • From first glance looks like the sql side isn't able to read `Revision` parameter. Can you double check the table at SQL side and type it accepts

    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Thursday, January 11, 2018 6:40 AM
  • Hello pianoboyCoder,

    Try the below code. (you need set the Revision column as bigint type matched long type in C#)

    	new SqlParameter("@INSTALLATION", "inst"),
    	new SqlParameter("@OBJNAM", "objName"),
    	new SqlParameter("@Key", "key"),
    	new SqlParameter("@Value", "value"),
    	new SqlParameter("@Deleted", false),
    	new SqlParameter("@ParamType", "Saved"),
    	new SqlParameter("@Revision",SqlDbType.BigInt){SqlValue=0L}

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 11, 2018 9:47 AM
    Moderator
  • Hello,

    Since you started a new question here which seems to use [key] as I recommended would this mean this question is resolved? You should always finish one post (in this case this one) before moving to a new post. So if my reply has resolved this issue mark it as answered.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, January 11, 2018 10:38 AM
    Moderator
  • Hello,

    If you are using 0L as a default value for Revision then why bother setting it but instead set the default value to 0L.

    Example

    ALTER TABLE ControlObjects ADD  CONSTRAINT constraintName  
       DEFAULT (0L) FOR [Revision]


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, January 11, 2018 10:50 AM
    Moderator
  • Ok, I change the type. How do I set the value to 0L? I am not for sure how the {SqlValue = 0L} is being use in my context of things.

    sqlResult = 0;
    sqlCommand = @"Insert INTO dbo.ControlObjects (INSTALLATION, Revision, OBJNAM, [Key], Value, Deleted, ParamType)" +
                  "VALUES (@INSTALLATION, @Revision, @OBJNAM, @Key, @Value, @Deleted, @ParamType)";
    
    sqlResult = this.Database.ExecuteSqlCommand(sqlCommand, 
                                                new SqlParameter("@INSTALLATION", installationId),
                                                new SqlParameter("@Revision", 0L), 
                                                new SqlParameter("@OBJNAM", objName),
                                                new SqlParameter("@Key", key),
                                                new SqlParameter("@Value", value),
                                                new SqlParameter("@Deleted", false), 
                                                new SqlParameter("@ParamType", "Saved")); 


    pianoboyCoder

    Thursday, January 11, 2018 6:25 PM
  • Try this change too:

       new SqlParameter("@Revision", value: 0L),

    otherwise @Revision is null.

    • Edited by Viorel_MVP Thursday, January 11, 2018 7:59 PM
    Thursday, January 11, 2018 7:57 PM
  • I had that from the beginning. I am confused on what you are telling me to change to? Look below, I already have that. That does not work.

    sqlResult = this.Database.ExecuteSqlCommand(sqlCommand, 
                                                new SqlParameter("@INSTALLATION", installationId),
                                                new SqlParameter("@Revision", 0L), 
                                                new SqlParameter("@OBJNAM", objName),
                                                new SqlParameter("@Key", key),
                                                new SqlParameter("@Value", value),
                                                new SqlParameter("@Deleted", false), 
                                                new SqlParameter("@ParamType", "Saved")); 


    pianoboyCoder

    Thursday, January 11, 2018 10:48 PM
  • I had that from the beginning. I am confused on what you are telling me to change to? Look below, I already have that. That does not work.

    sqlResult = this.Database.ExecuteSqlCommand(sqlCommand, 
                                                new SqlParameter("@INSTALLATION", installationId),
                                                new SqlParameter("@Revision", 0L), 
                                                new SqlParameter("@OBJNAM", objName),
                                                new SqlParameter("@Key", key),
                                                new SqlParameter("@Value", value),
                                                new SqlParameter("@Deleted", false), 
                                                new SqlParameter("@ParamType", "Saved")); 


    pianoboyCoder


    Try changing ‘new SqlParameter("@Revision", 0L)’ to ‘new SqlParameter("@Revision", value: 0L)’ and show the complete error text of your latest code.

    Friday, January 12, 2018 5:25 AM
  • That work. I do not get an error. Thanks for your help

    pianoboyCoder

    Friday, January 12, 2018 4:15 PM
  • Hello PianoboyCoder,

    Please don't forget to mark the helpful reply as answer if the issue has been solved, because this could be beneficial to other community members reading this thread.

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Sunday, January 14, 2018 12:34 PM
    Moderator