12 lines of code for a super simple IP address search engine (ASP. NET) event

Source: Internet
Author: User
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  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.