We help IT Professionals succeed at work.
Get Started

insert IPAddress into SQL server through detailsview

Last Modified: 2015-03-07
I need to collect user IP addresses. I cannot figure out what to put into template field TextBox of DetailsView to insert the IP addresses into SQL server.

Dim hostname As String = Server.HtmlEncode(Request.UserHostName)    

Here is the DetailsView and Insert command
 InsertCommand="INSERT INTO [table] ([IPAddress]) VALUES (@IPAddress)"
              <asp:Parameter Name="IPAddress" Type="String" />

          <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
                  DataKeyNames="ID" DataSourceID="SqlDataSource1" DefaultMode="Insert"
                  EnableModelValidation="True" Height="50px" Width="125px">
                      <asp:TemplateField HeaderText="IPAddress" SortExpression="IPAddress">
                              <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("IPAddress") %>'></asp:TextBox>
   <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("IPAddress")">'/>                  
                              <asp:Label ID="Label1" runat="server" Text='<%# Bind("IPAddress") %>'></asp:Label>
                      <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
                          ReadOnly="True" SortExpression="ID" />
                      <asp:CommandField ShowInsertButton="True" />
              <br />
Watch Question
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE