溢出错误 [英] overflow error

查看:113
本文介绍了溢出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我们如何只能在移动设备中插入10位数字,而不在其他文本字段中插入字符串

Note: how we can insert only 10-digit numbers in mobile no text field and only strings in other text fields


选项明确在
选项严格在
Imports System.Data
Imports System.Data。 OleDb

公共类注册
Dim连接作为OleDbConnection
Dim命令As OleDbCommand
Dim reader As OleDbDataReader
Dim conStr As String =" Provider = Microsoft .ACE.OLEDB.12.0;数据源= C:\Users\Admin \documents \ visual studio 2010 \Projects \ WindowsApplication289 \ WindowsApplication289 \ form1.accdb"
Dim query As String
Private Sub Register_Load(sender As System.Object,e As System.EventArgs)Handles MyBase.Load
txtFirstName.Text =""
txtLastName.Text =""
txtUsername.Text =""
txtPassword.Text =""
txtConfirmPassword.Text =""
txtMobileNo.Text =""
txtEmail.Text =""
txtFirstName.Focus()
End Sub

Private Sub btnSave_Click(sender As System.Object,e As System.EventArgs)处理btnSave.Click
If Len( Trim(txtFirstName.Text))= 0然后
MessageBox.Show(" Please Enter Your FirstName"," ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error)
txtFirstName.Focus()
退出Sub
结束如果
如果Len(Trim(txtLastName.Text))= 0则
MessageBox.Show(" Please Enter Your LastName"," ERROR",MessageBoxButtons)。 OK,MessageBoxIcon.Error)
txtLastName.Focus()
退出Sub
结束如果
如果Len(Trim(txtUsername.Text))= 0那么
MessageBox。显示("请输入您的用户名以访问您的帐户","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error)
txtUsername.Focus()
退出Sub
End如果
如果Len(Trim(txtPassword.Text))= 0则
MessageBox.Show("请为您的帐户输入您的密码","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error)
txtPassword.Focus()
退出Sub
结束如果
如果Len(Trim(txtConfirmPassword.Text))= 0那么
MessageBox.Show(" Please Confirm)您的密码通过重新键入","ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error)
txtConfirmPassword.Focus()
退出Sub
结束如果
如果Len(修剪) (txtMobileNo.Text))= 0然后
MessageBox.Show(" Please Enter Your Mobile No"," ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error)
txtMobileNo.Focus()
退出Sub
结束如果
如果Len(Trim(txtEmail.Text))= 0那么
MessageBox.Show("请输入您的电子邮件地址"," ; ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error)
txtEmail.Focus()
退出Sub
结束如果
尝试
connection =新OleDbConnection(conStr)
connection.ConnectionString = conStr
connection.Open()
query =" SELECT * from [reg] where [First Name] = @ fname AND [Last Name] = @ lname AND [Username ] = @ uname AND [密码] = @传递和[确认密码] = @ cpass AND [手机号码] = @ mobno和[电子邮件] = @ mail"
command = New OleDbCommand(query,connection)
command.Connection = connection
command.Parameters.AddWithValue(" @fname",txtFirstName.Text)
command.Parameters。 AddWithValue(" @lname",txtLastName.Text)
command.Parameters.AddWithValue(" @ uname",txtUsername.Text)
command.Parameters.AddWithValue(" @pass",txtPassword。文本)
command.Parameters.AddWithValue(" @cpass",txtConfirmPassword.Text)
command.Parameters.AddWithValue(" @ mobno",txtMobileNo.Text)
command.Parameters。 AddWithValue(" @mail",txtEmail.Text)
reader = command.ExecuteReader()
if reader.Read Then
MessageBox.Show(" Account already exists"& vbNewLine& amp; ;"请输入您的帐户","输入错误",MessageBoxButtons.OK,MessageBo xIcon.Error)
txtFirstName.Text =""
txtLastName.Text =""
txtUsername.Text =""
txtPassword.Text =""
txtConfirmPassword.Text =""
txtMobileNo.Text =""
txtEmail.Text =""
txtFirstName.Focus()
如果不是读者什么都没有那么
reader.Close()
结束如果
退出Sub
结束如果
connection = New OleDbConnection(conStr)
connection.ConnectionString = conStr
connection.Open()
query =" insert into [reg]([First Name],[Last Name],[用户名],[密码],[确认密码],[手机号码],[电子邮件])值('"& txtFirstName.Text&"','"& txtLastName.Text&"' ,'"& txtUsername.Text&"','"& txtPassword.Text&"','"& txtConfirmPassword.Text&"','"& txtMobileNo。 Text&"','"& txtEmail.Text&"')"
command = New OleDbCommand(query,connection)
command.ExecuteNonQuery()
MessageBox.Show(" Data Saved Successfully"," Record",MessageBoxButtons.OK,MessageBoxIcon.Information)
command.Dispose()
connection.Close()
Me.Hide()
Form1.Show()
Catch ex As Exception
MsgBox( ex.Message,MsgBoxStyle.Critical,MsgBoxResult.Ok)
End Try
End Sub

Private Sub btnClear_Click(sender As System.Object,e As System.EventArgs)处理btnClear 。点击
txtFirstName.Text =""
txtLastName.Text =""
txtUsername.Text =""
txtPassword.Text =""
txtConfirmPassword.Text =""
txtMobileNo.Text =""
txtEmail.Text =""
txtFirstName.Focus()
End Sub

Private Sub btnExit_Click(sender As System.Object,e As System.EventArgs)处理btnExit.Click
Application.Exit ()
End Sub

Private Sub txtEmail_Validating(sender As Object,e As System.ComponentModel.CancelEventArgs)处理txtEmail.Validating
Dim rEMail As New System.Text.RegularExpressions。正则表达式(QUOT; ^ [A-ZA-Z] [\w\ .-] {2,28} [A-ZA-Z0-9] @ [A-ZA-Z0-9] [\w\\ \\ .-] * [a-zA-Z0-9] \。[a-zA-Z] [a-zA-Z \。] * [a-zA-Z] $")
如果txtEmail.Text.Length> 0然后
如果不是rEMail.IsMatch(txtEmail.Text)那么
MessageBox.Show(" invalid email address"," Error",MessageBoxButtons.OK,MessageBoxIcon。[Error])
txtEmail.SelectAll()
e.Cancel = True
End if
End if
End Sub
End Class

Option Explicit On Option Strict On Imports System.Data Imports System.Data.OleDb Public Class Register Dim connection As OleDbConnection Dim command As OleDbCommand Dim reader As OleDbDataReader Dim conStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Admin\documents\visual studio 2010\Projects\WindowsApplication289\WindowsApplication289\form1.accdb" Dim query As String Private Sub Register_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load txtFirstName.Text = "" txtLastName.Text = "" txtUsername.Text = "" txtPassword.Text = "" txtConfirmPassword.Text = "" txtMobileNo.Text = "" txtEmail.Text = "" txtFirstName.Focus() End Sub Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click If Len(Trim(txtFirstName.Text)) = 0 Then MessageBox.Show("Please Enter Your FirstName", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error) txtFirstName.Focus() Exit Sub End If If Len(Trim(txtLastName.Text)) = 0 Then MessageBox.Show("Please Enter Your LastName", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error) txtLastName.Focus() Exit Sub End If If Len(Trim(txtUsername.Text)) = 0 Then MessageBox.Show("Please Enter Your UserName To Access Your Account", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error) txtUsername.Focus() Exit Sub End If If Len(Trim(txtPassword.Text)) = 0 Then MessageBox.Show("Please Enter Your Password For Your Account", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error) txtPassword.Focus() Exit Sub End If If Len(Trim(txtConfirmPassword.Text)) = 0 Then MessageBox.Show("Please Confirm Your Password By Re-Typing", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error) txtConfirmPassword.Focus() Exit Sub End If If Len(Trim(txtMobileNo.Text)) = 0 Then MessageBox.Show("Please Enter Your Mobile No", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error) txtMobileNo.Focus() Exit Sub End If If Len(Trim(txtEmail.Text)) = 0 Then MessageBox.Show("Please Enter Your Email Address", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error) txtEmail.Focus() Exit Sub End If Try connection = New OleDbConnection(conStr) connection.ConnectionString = conStr connection.Open() query = "SELECT * from [reg] where [First Name]=@fname AND [Last Name]=@lname AND [Username]=@uname AND [Password]=@pass AND [Confirm password]=@cpass AND [Mobile No]=@mobno AND [Email]=@mail" command = New OleDbCommand(query, connection) command.Connection = connection command.Parameters.AddWithValue("@fname", txtFirstName.Text) command.Parameters.AddWithValue("@lname", txtLastName.Text) command.Parameters.AddWithValue("@uname", txtUsername.Text) command.Parameters.AddWithValue("@pass", txtPassword.Text) command.Parameters.AddWithValue("@cpass", txtConfirmPassword.Text) command.Parameters.AddWithValue("@mobno", txtMobileNo.Text) command.Parameters.AddWithValue("@mail", txtEmail.Text) reader = command.ExecuteReader() If reader.Read Then MessageBox.Show("Account already exists" & vbNewLine & "Please enter your account", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error) txtFirstName.Text = "" txtLastName.Text = "" txtUsername.Text = "" txtPassword.Text = "" txtConfirmPassword.Text = "" txtMobileNo.Text = "" txtEmail.Text = "" txtFirstName.Focus() If Not reader Is Nothing Then reader.Close() End If Exit Sub End If connection = New OleDbConnection(conStr) connection.ConnectionString = conStr connection.Open() query = "insert into [reg]([First Name],[Last Name],[Username],[Password],[Confirm Password],[Mobile No],[Email]) values('" & txtFirstName.Text & "','" & txtLastName.Text & "','" & txtUsername.Text & "','" & txtPassword.Text & "','" & txtConfirmPassword.Text & "','" & txtMobileNo.Text & "','" & txtEmail.Text & "')" command = New OleDbCommand(query, connection) command.ExecuteNonQuery() MessageBox.Show("Data Saved Successfully", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information) command.Dispose() connection.Close() Me.Hide() Form1.Show() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, MsgBoxResult.Ok) End Try End Sub Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click txtFirstName.Text = "" txtLastName.Text = "" txtUsername.Text = "" txtPassword.Text = "" txtConfirmPassword.Text = "" txtMobileNo.Text = "" txtEmail.Text = "" txtFirstName.Focus() End Sub Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click Application.Exit() End Sub Private Sub txtEmail_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles txtEmail.Validating Dim rEMail As New System.Text.RegularExpressions.Regex("^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$") If txtEmail.Text.Length > 0 Then If Not rEMail.IsMatch(txtEmail.Text) Then MessageBox.Show("invalid email address", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error]) txtEmail.SelectAll() e.Cancel = True End If End If End Sub End Class







推荐答案

如果你遇到一个问题(你没有提及)然后INSERT查看字段的字段定义,例如它们的长度,看它们是否足够大以容纳您的数据。否则请说明有关
操作和行的错误。
If you are having an issue with (which you didn't mention) with an INSERT then look at the field definitions of the fields e.g. their length to see if they are large enough to hold your data. Otherwise please indicate where the error is in regards to the operation and line.


这篇关于溢出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆