We help IT Professionals succeed at work.
Get Started

insert IPAddress into SQL server through detailsview

149 Views
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)"
          <InsertParameters>
              <asp:Parameter Name="IPAddress" Type="String" />
          </InsertParameters>

          <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
                  DataKeyNames="ID" DataSourceID="SqlDataSource1" DefaultMode="Insert"
                  EnableModelValidation="True" Height="50px" Width="125px">
                  <Fields>
                      <asp:TemplateField HeaderText="IPAddress" SortExpression="IPAddress">
                          <EditItemTemplate>
                              <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("IPAddress") %>'></asp:TextBox>
                          </EditItemTemplate>
                          <InsertItemTemplate>                        
   <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("IPAddress")">'/>                  
                            </InsertItemTemplate>
                          <ItemTemplate>
                              <asp:Label ID="Label1" runat="server" Text='<%# Bind("IPAddress") %>'></asp:Label>
                          </ItemTemplate>
                      </asp:TemplateField>
                      <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
                          ReadOnly="True" SortExpression="ID" />
                      <asp:CommandField ShowInsertButton="True" />
                  </Fields>
              </asp:DetailsView>
              <br />
Comment
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