using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Configuration; using System.Data.SqlClient; namespace 号码归属地查询 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { string conn=ConfigurationManager.ConnectionStrings["conn"].ConnectionString; string number,num; number = textBox1.Text.Trim(); num = number.Substring(0,7); using (SqlConnection sqlconn = new SqlConnection(conn)) { sqlconn.Open(); SqlCommand comm = sqlconn.CreateCommand(); comm.CommandText = "select * from list where num='"+num+"'"; SqlDataReader read = comm.ExecuteReader(); if (!read.Read()) { MessageBox.Show("没有您要找的号码的归属地!"); } else { lb_City.Text = read.GetString(read.GetOrdinal("city")); lb_num.Text = read.GetString(read.GetOrdinal("code")); lb_stype.Text = read.GetString(read.GetOrdinal("cardtype")); } } } private void textBox1_KeyPress(object sender,KeyPressEventArgs e) { if (e.KeyChar<='z'&&e.KeyChar>='a') { e.Handled =true; } if (textBox1.Text.Length == 11) { textBox1.ForeColor = System.Drawing.Color.Red; } } } } <img src="http://hi.csdn.net/attachment/201101/15/0_1295110690g8Nx.gif" mce_src="http://hi.csdn.net/attachment/201101/15/0_1295110690g8Nx.gif" alt="" width="422" height="279" /></b>
欢迎访问我的独立博客,博客地址http://yywang.info
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架