本文介绍了如何在文本框中验证输入数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 protected void bindgrid() { string strConnString = ConfigurationManager.ConnectionStrings [ DatabaseConnectionString ]的ConnectionString。 SqlConnection conn = new SqlConnection(strConnString); DataTable dtab = new DataTable(); string query = SELECT [FirstName],[LastName],[Address],[City],[Country],[Age],[Sex],[Status],[Ethnic],[Occupation],[EmailAddress],[Password],[ ImageFilename] FROM [ProfileTbl] Where LastName =' + txtSearch.Text + ' ; SqlDataAdapter sqlda = new SqlDataAdapter(query,conn); conn.Open(); sqlda.Fill(dtab); if (dtab.Rows.Count > 0 ) { GridView1.DataSource = dtab; GridView1.DataBind(); } conn.Close(); 受保护 void btnSearch_Click( object sender,EventArgs e) { bindgrid(); } 当我从数据库查询LastName(例如:Smith)时,数据库记录中的所有Smith将出现或显示在gridview中。我问题是,如果我搜索不在数据库记录中的琼斯,我只想提示一条消息,即未找到记录..如何验证该语句?是如果还有条件?.. 我对你的想法持开放态度。请给我一个想法.. 解决方案 protected void bindgrid() {string strConnString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(strConnString); DataTable dtab = new DataTable(); string query = "SELECT [FirstName],[LastName],[Address],[City],[Country],[Age],[Sex],[Status],[Nationality],[Occupation],[EmailAddress],[Password],[ImageFilename] FROM [ProfileTbl] Where LastName='"+txtSearch.Text+"'"; SqlDataAdapter sqlda = new SqlDataAdapter(query, conn); conn.Open(); sqlda.Fill(dtab); if (dtab.Rows.Count > 0) { GridView1.DataSource = dtab; GridView1.DataBind(); } conn.Close(); protected void btnSearch_Click(object sender, EventArgs e) { bindgrid(); }When I query the LastName (for example:Smith)from database..All Smith in database record will appear or display to the gridview..My question is, if i search "Jones" which is not in the database record, I just want to prompt a message which is "Record not found"..how to validate that statements? is it "if else condition?"..I am open to your all idea.Give me an idea for this.. 解决方案 这篇关于如何在文本框中验证输入数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-15 20:21