本文介绍了如何验证gridview页脚文本框中已插入的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 嗨Frnds, 我想验证记录,如果已存在则显示消息记录已存在。 如果是新的记录,它必须插入。 在这里我有3个字段作为用户名,员工编号,电子邮件。 不得再次插入现有用户名。 不得再次插入现有。 不得再次插入现有电子邮件。 所以它应该验证,当在gridview页脚中添加按钮点击时。 ------------ -------------------- 所以,这是我的代码....Hi Frnds,I want to validate records, if it already exists show message Record already exists.If it is new record, it must insert.In this i have 3 fields as Username,EmployeeNumber, Email.Existing username must not be inserted once again.Existing must not be inserted once again.Existing Email must not be inserted once again.so it should validate, when add button clicks in gridview footer.--------------------------------So, this is my code....protected void GVRegistrations_RowCommand(object sender, GridViewCommandEventArgs e) {if (e.CommandName.Equals("AddNew Registrations")) { TextBox TxtUserName= (TextBox)GVRegistrations.FooterRow.FindControl("TxtFOOTERUserName"); TextBox EmployeeNumber= (TextBox)GVRegistrations.FooterRow.FindControl("TxtFOOTEREmpNo"); TextBox TxtEmail = (TextBox)GVRegistrations.FooterRow.FindControl("TxtFOOTEREmail"); con.Open(); SqlCommand cmd = new SqlCommand("SELECT Count(*) FROM ACRegistrations where UserName= '" + TxtUserName.Text + "'", con); int count = int.Parse(cmd.ExecuteScalar() + ""); if (count == 0) { cmd = new SqlCommand("INSERT into ACRegistrations(UserName,EmployeeNumber,Email) values('" + TxtUserName.Text + "','" + EmployeeNumber.Text + "','" + TxtEmail.Text + "')", con); int result = cmd.ExecuteNonQuery(); if (result == 1) { BindRegistrations(); ScriptManager.RegisterStartupScript(this, this.GetType(), "RunCode", "javascript:alert('Record Added successfully');", true); } } else { ScriptManager.RegisterStartupScript(this, this.GetType(), "RunCode", "javascript:alert('Sorry, This Record already exists');", true); } } con.Close();} 我想验证三个字段,一个接一个 请帮助我,提前谢谢。I want to validate three fields, one after the otherPlease help me, Thanks in advance.推荐答案"SELECT Count(*) FROM ACRegistrations where UserName= '" + TxtUserName.Text + "' or EmployeeNumber='" + EmployeeNumber.Text + "' or Email='" + TxtEmail.Text +"'";"SELECT Count(*) FROM ACRegistrations where UserName= '" + TxtUserName.Text.Trim() + "' or EmployeeNumber='" + EmployeeNumber.Text.Trim() + "' or Email='" + TxtEmail.Text.Trim() +"'"; 如果Count大于1,请不要插入警告用户,否则插入错误消息。if Count is greater than one dont insert alert user with error message else insert. 这篇关于如何验证gridview页脚文本框中已插入的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 03:46