none
Conversion from NVarChar to int Failed

    Question

  • I am trying to store an IP Address into a SQL Table column that's declared as NVarChar, but when I run the code it comes back with this:

    Conversion failed when converting the nvarchar value '192.168.0.1' to data type int
    

    Why is it trying to convert it to an integer?  Way I have it working is that I run a ping command and I assign IP Address to a String as so:

    currentIP = reply.Address.ToString();

    Then I pass currentIP to a parameter in the method that imports it into a SQL Table.  Does anyone know why its doing this?

    Thursday, August 02, 2012 6:55 PM

Answers

  • If you are doing a direct insert, do your columns align with your inserted values?

    INSERT INTO MyTable
       (col1, col2, col3, ..., coln)
    VALUES
       (val1, val2, val3, ..., valn)

    If you are calling a stored procedure, are your parameter names correct?

    David Downing... If this answers your question, please Mark as the Answer. If this post is helpful, please vote as helpful.




    • Edited by David K. Downing Thursday, August 02, 2012 7:10 PM
    • Marked as answer by Granidier Thursday, August 02, 2012 7:25 PM
    Thursday, August 02, 2012 7:04 PM

All replies

  • If you are doing a direct insert, do your columns align with your inserted values?

    INSERT INTO MyTable
       (col1, col2, col3, ..., coln)
    VALUES
       (val1, val2, val3, ..., valn)

    If you are calling a stored procedure, are your parameter names correct?

    David Downing... If this answers your question, please Mark as the Answer. If this post is helpful, please vote as helpful.




    • Edited by David K. Downing Thursday, August 02, 2012 7:10 PM
    • Marked as answer by Granidier Thursday, August 02, 2012 7:25 PM
    Thursday, August 02, 2012 7:04 PM
  • If you are doing a direct insert, do your columns align with your inserted values?

    INSERT INTO MyTable
       (col1, col2, col3, ..., coln)
    VALUES
       (val1, val2, val3, ..., valn)

    If you are calling a stored procedure, are your parameter names correct?

    David Downing... If this answers your question, please Mark as the Answer. If this post is helpful, please vote as helpful.




    Wow, I don't know how I missed that : )  My insert into and values were not aligned.  Thanks for pointing that out.  It works now.
    Thursday, August 02, 2012 7:25 PM