Conversion from NVarChar to int Failed

Traitée Conversion from NVarChar to int Failed

  • jeudi 2 août 2012 18:55
     
      A du code

    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?

Toutes les réponses

  • jeudi 2 août 2012 19:04
     
     Traitée A du code

    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.




  • jeudi 2 août 2012 19:25
     
      A du code

    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.