Conversion from NVarChar to int Failed
-
jeudi 2 août 2012 18:55
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
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.
- Modifié David K. Downing jeudi 2 août 2012 19:10
- Marqué comme réponse Granidier jeudi 2 août 2012 19:25
-
jeudi 2 août 2012 19:25
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.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.

