none
what I should change for the error message RRS feed

  • Question

  • Hi, I got theis error when I run the application, Please acdvise

    • Moved by Naomi NModerator Thursday, March 22, 2012 3:06 PM Better answer can be here (From:Transact-SQL)
    Thursday, March 22, 2012 3:01 PM

Answers

  • SqlParameter Param = new SqlParameter("NTD",SqlDbType.VarChar,50);
    Param.Value = ID().Trim();
    dap.SelectCommand.Parameters.Add(Param);


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    • Edited by Naomi NModerator Thursday, March 22, 2012 3:07 PM
    • Marked as answer by KJian_ Thursday, March 29, 2012 8:52 AM
    Thursday, March 22, 2012 3:05 PM
    Moderator
  • dap.SelectCommand.Parameters.Add(new SQLParameter("NTID", SqlDbType.varchar, 50).Value = ID().Trim());

    here, "new SQLParameter("NTID", SqlDbType.varchar, 50).Value = ID().Trim()" is a C# expression where you are doing the following

    • Creating a new SQL Parameter.
    •  Used "=" operator, which does the job of assigning the ID().Trim() value to the parameter. So now the whole expression is not of SQLParameter type but of the type of string.
    •  Passing the string value to dap.SelectCommand.Parameters.Add() method and thus throwing the exception.

    This code should not be compilable even, I guess you have changed in source code and directly executing from the browser.

    Solution: Add the new parameter in a new line and assign the value in a different line. (Typed in Notepad. Check for syntax.)


    SQLParameter param1 = new SQLParameter("NTID", SqlDbType.varchar, 50); param1.Value = ID().Trim(); dap.SelectCommand.Parameters.Add(param1);


    Welcome to MSDN Forums.
    Feel free to ask your questions and Please Note to Vote all helpful topics and Mark all answering posts.

    You Value Community's efforts and Community values your faith.
    - Arun Kumar Allu

    • Marked as answer by KJian_ Thursday, March 29, 2012 8:52 AM
    Thursday, March 22, 2012 3:17 PM

All replies

  • SqlParameter Param = new SqlParameter("NTD",SqlDbType.VarChar,50);
    Param.Value = ID().Trim();
    dap.SelectCommand.Parameters.Add(Param);


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    • Edited by Naomi NModerator Thursday, March 22, 2012 3:07 PM
    • Marked as answer by KJian_ Thursday, March 29, 2012 8:52 AM
    Thursday, March 22, 2012 3:05 PM
    Moderator
  • It seems you are using the Varchar instead of numeric or integer.


    Thanks
    Manish

    Please use Mark as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    Thursday, March 22, 2012 3:05 PM
  • dap.SelectCommand.Parameters.Add(new SQLParameter("NTID", SqlDbType.varchar, 50).Value = ID().Trim());

    here, "new SQLParameter("NTID", SqlDbType.varchar, 50).Value = ID().Trim()" is a C# expression where you are doing the following

    • Creating a new SQL Parameter.
    •  Used "=" operator, which does the job of assigning the ID().Trim() value to the parameter. So now the whole expression is not of SQLParameter type but of the type of string.
    •  Passing the string value to dap.SelectCommand.Parameters.Add() method and thus throwing the exception.

    This code should not be compilable even, I guess you have changed in source code and directly executing from the browser.

    Solution: Add the new parameter in a new line and assign the value in a different line. (Typed in Notepad. Check for syntax.)


    SQLParameter param1 = new SQLParameter("NTID", SqlDbType.varchar, 50); param1.Value = ID().Trim(); dap.SelectCommand.Parameters.Add(param1);


    Welcome to MSDN Forums.
    Feel free to ask your questions and Please Note to Vote all helpful topics and Mark all answering posts.

    You Value Community's efforts and Community values your faith.
    - Arun Kumar Allu

    • Marked as answer by KJian_ Thursday, March 29, 2012 8:52 AM
    Thursday, March 22, 2012 3:17 PM
  • Which error are you getting please post proper description? There is no description that i can see. Is it because it is moved to Transact SQL?
    Thursday, March 22, 2012 4:52 PM
  • Hello,

    Maybe, it would be useful to provide the full definition of the stored procedure of which the name is in the procName variable or at least the header part where the parameters are defined ...

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.


    Saturday, March 24, 2012 11:18 AM
    Moderator
  • Hello sdnd_2000,

    Please, could you tell us whether your problem has been solved ? If not , please, could you tell us what is ID() ? A function , that's sure, but how is it  working  and what is the data type of the returned value by this function ?

    If it is solved, please, could you provide your solution with explanations ? It could be useful for visitors of this forum having the same problem.

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    Tuesday, March 27, 2012 1:32 PM
    Moderator