Page design:
Running effect:
Of course, this requires a database file with an IP address. I used wry. dll from the Internet, changed it to wry. DBF, and then imported it to SQL Server. I converted the file into Access 2000 format and uploaded it. Http://files.cnblogs.com/lqb/Database1.rar
You can add the database to SQL Server through the promotion Wizard of access 2003/2007, or you can useSelect * IntoNewtable
From OpenDataSource('Microsoft. Jet. oledb.4.0',
'Data Source = "D: \ database1.mdb"') Wry
To import data. References (three points before the table name)
With data, you can create a project. add textbox, button, and gridview controls.
Default. aspx. CS Protected Void Button#click ( Object Sender, eventargs E)
{
String [] = Textbox1.text. Trim (). Split ( ' . ' );
String B = "" ;
For ( Int I = 0 ; I < 4 ; I ++ )
B + = " 0000 " . Remove ( 3 - A [I]. length) + A [I];
// Handle IP addresses
String Con = " Data Source = LQB-PC \ sqlexpress; initial catalog = iptable; Integrated Security = true " ;
String SQL = " Select startip, endip, country, local from IP where (substring (startip, 1, 3) + substring (startip, 5, 3) + substring (startip, 9, 3) + substring (startip, 13, 3) <= '~ 1') and (substring (endip, 1, 3) + substring (endip, 5, 3) + substring (endip, 9, 3) + substring (endip, 13, 3)> = '~ 1 ') order by local DESC, startip DESC " ;
SQL = SQL. Replace ( " ~ 1 " , B );
// Complete the connection string
Sqldataadapter Adapter = New Sqldataadapter (SQL, con );
Dataset DS = New Dataset ();
Adapter. Fill (DS );
Gridview1.datasource = DS. Tables [ 0 ];
Gridview1.databind ();
}
I accidentally exposed a small habit. SQL = " Select * from table where id =' " + Textbox1.text + " 'And name =' " + Textbox2.text + " ' " ;
The more parameters it takes, the more messy it will be. I use it directly ~ 1 ~ 2 ~ 3 instead, and thenSQL=SQL. Replace ("~ 1", Textbox1.text). Replace ("~ 2", Textbox2.text );
On the one hand, it will not be disturbed by '"+ +"'. On the other hand, it is also for good looks! Xi ~
HereProgramThis is done. The most useful SQL statement is the long SQL statement, because the substring method is used to compare the Combined Strings. Finally, the content that meets the condition is returned.
I also found that many functions are available in SQL today, which is much more convenient to use. Prepare to sort out the functions supported by SQL as soon as possible, including usage and examples.
PS: it is easier to replace the preceding SQL statement with this statement. Select Startip, endip, country, local
From IP
Where ( Replace (Startip, ' . ' , '' ) <= ' ~ 1 ' ) And ( Replace (Endip, ' . ' , '' ) > = ' ~ 1 ' )
Order By Local Desc , Startip Desc