验证文本框值 [英] Validating Text Box Value
本文介绍了验证文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
谁能告诉我如何验证文本框的值?我有一个带有用于验证sql表的重复值的函数的类.
功能:
[代码]
Hi ALL,
Can anyone tell me how to validate the text box value? I have one class with function for validating the duplicate value of sql table.
Function:
[code]
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows.Forms
Public Class vDesignationSetup
Dim oFunc As New hrSQLConn.SQLConnection
Dim strINIPath As String = Application.StartupPath + "\BDFCLHR.INI"
'Dim OLEDBConn As New OleDb.OleDbConnection '(strINIPath)
Dim SQLConn As New OleDb.OleDbConnection
Dim oDsDr As OleDb.OleDbDataReader
Dim dsSQL As String
Public Function DesignationNameExists(ByVal sDesignationName As String) As Boolean
Try
dsSQL = "SELECT DesName FROM dbo.hrDesignationSetup WHERE DesName = '" & sDesignationName & "'"
Dim dsCommand As New OleDb.OleDbCommand(dsSQL, SQLConn)
SQLConn.ConnectionString = oFunc.GetConnectionString(strINIPath)
SQLConn.Open()
oDsDr = dsCommand.ExecuteReader()
DesignationNameExists = oDsDr.HasRows
oDsDr.Close()
SQLConn.Close()
Catch ex As Exception
Throw ex
End Try
End Function
Public Function DShortNameExists(ByVal sDShortName As String) As Boolean
Try
dsSQL = "SELECT DesShortName FROM dbo.hrDesignationSetup WHERE DesShortName = '" & sDShortName & "'"
Dim dsCommand As New OleDb.OleDbCommand(dsSQL, SQLConn)
SQLConn.ConnectionString = oFunc.GetConnectionString(strINIPath)
SQLConn.Open()
oDsDr = dsCommand.ExecuteReader()
DShortNameExists = oDsDr.HasRows
oDsDr.Close()
SQLConn.Close()
Catch ex As Exception
Throw ex
End Try
End Function
End Class
[/code]
Save Button Code:
[code]
Private Sub btnedsSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnedsSave.Click
If ValidateData() Then
If vilDesignation.DesignationNameExists(edsDesigName.Text.Trim) Then
MessageBox.Show("Designation Name [" & edsDesigName.Text.Trim & "] already exists. Please Check.", "Data Validation", MessageBoxButtons.OK, MessageBoxIcon.Warning)
edsDesigName.Focus()
Exit Sub
ElseIf vilDesignation.DShortNameExists(edsDesShortName.Text.Trim) Then
MessageBox.Show("Designation Short Name [" & edsDesShortName.Text.Trim & "] already exists. Please Check.", "Data Validation", MessageBoxButtons.OK, MessageBoxIcon.Warning)
edsDesShortName.Focus()
Exit Sub
ElseIf (edsDefaultCheckbox.Checked) Then
If vilDesignation.CheckBoxValidation(True) Then
MessageBox.Show("Another Designation already set as Default. Please check", "Data Validation", MessageBoxButtons.OK, MessageBoxIcon.Information)
edsDefaultCheckbox.Focus()
Exit Sub
Else
btnedsSave.Focus()
End If
End If
Try
If bNewData Then
SQLConn.Open()
trns = SQLConn.BeginTransaction
InsertCMD()
trns.Commit()
SQLConn.Close()
GetData()
bNewData = False
bEditData = False
Count()
MessageBox.Show("Record Saved Successfully", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information)
EnableControlsLoadMode(True)
Else
SQLConn.Open()
trns = SQLConn.BeginTransaction
UpdateCMD()
trns.Commit()
SQLConn.Close()
GetData()
bNewData = False
bEditData = False
Count()
MessageBox.Show("Record Updated Successfully", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information)
EnableControlsLoadMode(True)
End If
Catch ex As Exception
trns.Rollback()
MessageBox.Show("Critical Error!" & ex.Message, "Critical Error.", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
End Sub
[/code]
问题:
上面的代码虽然在添加新数据时进行验证有效,但在更新时不起作用.
请帮助.....
[/code]
Problem:
The above code while validating when adding new data is working, but while updating its not working.
Please help.....
推荐答案
有很多代码,因此请尝试通过使用调试器并检查问题的发生方式来缩小问题的范围.
一种可能性是,如果对现有行的检查不起作用,则yuo在与数据库的比较中可能会出现不匹配的情况.一件事是,您应该使用 SqlParameter [ ^ ]而不是串联的语句中的文字.另外,如果问题是找不到行,请检查排序规则设置,以及是否将大写和小写字母字符视为不同的字符.
There is lots of code so try to narrow your problem by using the debugger and checking how the problem occurs.
One possibility is that if the check for existing rows isn''t working, yuo could have a mismatch in the comparison against the database. One thing is that you should use SqlParameter[^] in your queries instead of concatenated literals in the statement. Also if the problem is that the row isn''t found, check your collation settings and if upper and lower case characters are handled as different characters.
u请按照以下步骤操作并验证文本框.
1.文本框onblur()调用一个Java脚本函数
2.在该函数中调用客户端Ajax
3.在该ajax中,您发现数据库中是否存在该值.你有任何回应都会回来.(是/否)
4.在Java脚本中验证该值并显示警报框.
5.如果已经存在,则将焦点放在相同的测试箱中
否则请转到下一个..
u follow this steps and validating text box.
1. textbox box onblur() call one java script function
2. in that function call client side ajax
3. in that ajax u find that value is there or not in database. u come back with any response.(Y/N)
4. in java script validate that value and show alert boxes.
5.if already exists then focus same testbox
otherwise go to next..
这篇关于验证文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文