LessIsMore
asked on
insert IPAddress into SQL server through detailsview
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. UserHostNa me)
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="SqlDataSourc e1" DefaultMode="Insert"
EnableModelValidation="Tru e" 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 />
Dim hostname As String = Server.HtmlEncode(Request.
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="SqlDataSourc
EnableModelValidation="Tru
<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 />
ASKER
I am collecting IP addresses from users of aspx page and need to insert it into table.
Hi,
You mean you want to collect the IP addresses used by users when they access your ASP page?? if it's the case you need to code a script that will get the IP from users sessions and insert it to the SQL!
The example you provide is a form with text boxes witch mean, the IP values will be filled in the page and then inserted to the databse!
Please explain well your need.
Regards.
Salah
You mean you want to collect the IP addresses used by users when they access your ASP page?? if it's the case you need to code a script that will get the IP from users sessions and insert it to the SQL!
The example you provide is a form with text boxes witch mean, the IP values will be filled in the page and then inserted to the databse!
Please explain well your need.
Regards.
Salah
ASKER
I get IP value with the first line of code. I just need the way to use this value in detailview to submit it to sql server table. I might not use detailsview but do not know how to use it in sql insert statement.
ASKER
Here is the logic.
My user goes to the page. I am capturing his IP address by .
Dim hostname As String = Server.HtmlEncode(Request. UserHostNa me)
How to insert hostname in SQL server?
My user goes to the page. I am capturing his IP address by .
Dim hostname As String = Server.HtmlEncode(Request.
How to insert hostname in SQL server?
Hi,
Here is a sample where "Colums1" correpond to Hostname colums in your table and "hostname" is your variable defined by Dim:
Set objConn = ConnectDB()
query = "INSERT INTO table (Colums1,Colums2,Colums3,C olumsx) VALUES ('"& hostname &"','"& variable2 &"','"& variable3 &"','"& variablex &"')"
Set objs = objConn.Execute(query)
Regards.
Salah
Here is a sample where "Colums1" correpond to Hostname colums in your table and "hostname" is your variable defined by Dim:
Set objConn = ConnectDB()
query = "INSERT INTO table (Colums1,Colums2,Colums3,C
Set objs = objConn.Execute(query)
Regards.
Salah
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Hi,
This was just an example which you need to adapt to you script coding page, you can display the result first in the page in order to make sure the variable and script is providing output result correctly then change the code to insert values into DB with proper connection parameters you are working with.
Meanwhile, if your problem was solved please close the question.
Regards.
Salah
This was just an example which you need to adapt to you script coding page, you can display the result first in the page in order to make sure the variable and script is providing output result correctly then change the code to insert values into DB with proper connection parameters you are working with.
Meanwhile, if your problem was solved please close the question.
Regards.
Salah
ASKER
The provided by experts solutions did not work for me.
Your question is confused!! you want to collect the IP addresses witch mean query the SQL? or you want to update the IPs by insert??
Regards.
Salah