0

I have a stored procedure that inserts a few columns into a database, IP Address, Name, Comments. I am not sure how to get the ip address of the users machine. Perhaps I am to create a variable of the same type (INT) and then store the IP Address in there. I am kinda of lost on this one.

static int IPAddress()
{ 
get { return Request.UserHostAddress; }; 
}//How do I pass from here into my stored procedure?


                cmdI.Parameters.Add(new SqlParameter("@IPAddress", cmdI));
                cmdI.Parameters.Add(new SqlParameter("@Name", cmdI));
                cmdI.Parameters.Add(new SqlParameter("@Comments", cmdI));
Chandu
  • 74,913
  • 16
  • 123
  • 127
jpavlov
  • 2,165
  • 8
  • 42
  • 57

2 Answers2

1

You need to convert the IP Address from a string to an int; see How to convert an IPv4 address into a integer in C#?

However, I would change the DB to store IP address as a string. This way you will support IPv6.

Community
  • 1
  • 1
Richard Schneider
  • 33,296
  • 8
  • 52
  • 68
-1

IP address is indeed a representation of a 32bit int and can be stored in the db as such

Variant
  • 16,291
  • 4
  • 37
  • 64
  • 1
    Have a look here: http://stackoverflow.com/questions/461742/how-to-convert-an-ipv4-address-into-a-integer-in-c – Variant Jul 04 '11 at 22:27