资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net校验和 vbnet byval

VB.NET如何对输入的数据进行合法性检验,过滤不合法的数据代码

合法性校验有很多方法,要视情况而定,比如说可以用正则表达式,如果是数字,除了正则表达式,也可以用诸如TryParse这种方法。

10年积累的成都做网站、网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先做网站设计后付款的网站建设流程,更有定海免费网站建设让你可以放心的选择与我们合作。

vb.net 点击一个叫button1的按钮 用COM1发送(接收) 假设八位数据位,有奇偶校验位

这是我的简单串口代码:

Dim a As Integer

Dim b As Variant

Private Sub u_Click()

Text1.Text = "请先设置波特率与COM口!!!"

End Sub

Private Sub Cbo1_Click()

On Error GoTo blak '打开串口发生错误,提示信息

If MSComm1.PortOpen = True And a = 1 Then

MSComm1.PortOpen = False '必须先关闭端口,再对端口进行设置

MSComm1.CommPort = cbo1.ListIndex + 1 '端口号从0开始,必须加1

Else '有必要

MSComm1.CommPort = cbo1.ListIndex + 1

End If '注释的必须有,为第二次切换做准备,否则第二次换COM口会出问题

Exit Sub

blak:

MsgBox "串口不存在或被占用!", vbOKOnly, "提示信息" '必须是这种格式

End Sub

Private Sub Cbo2_Click() '单击事件,不是change事件

MSComm1.Settings = 1200 * 2 ^ cbo2.ListIndex "n,8,1" '设置端口的波特率,连接符前后必须空一格

End Sub

Private Sub cmd1_Click()

a = a + 1

If a = 1 Then

cmd1.Caption = "关闭串口"

cbo1.Enabled = False

MSComm1.PortOpen = True '打开串口

ElseIf a = 2 Then

cmd1.Caption = "打开串口"

cbo1.Enabled = True

MSComm1.PortOpen = False '关闭串口

a = 0

End If

End Sub

Private Sub cmd2_Click()

Text1.Text = "" '清空接收区

Text2.SetFocus

End Sub

Private Sub cmd3_Click()

Text2.Text = "" '清空发送区

Text2.SetFocus

End Sub

Private Sub cmd4_Click()

Dim d As Integer

Dim e(0) As Byte 'outbyte 输出字符

d = Val(Text2.Text)

e(0) = CByte(d)

MSComm1.OutBufferCount = 0 '清除发送缓冲区

MSComm1.Output = e '此命令执行一次发送8字节

End Sub

Private Sub Form_Load()

cbo1.ListIndex = 0

cbo2.ListIndex = 0

MSComm1.OutBufferCount = 0

MSComm1.InBufferCount = 0

End Sub

Private Sub MSComm1_OnComm()

Select Case MSComm1.CommEvent '返回最近的通信过程

Case comEvReceive '接受的数据

c: b = MSComm1.Input

If Option1.Value = True Then

Text3.Text = Text1.Text Hex(b(0)) '首次不行,因为有字符

Text1.Text = Text3.Text " " '转换一下

ElseIf Option2.Value = True Then

Text1.Text = Text1.Text b ""

End If

If MSComm1.InBufferCount 0 Then 'mscomm1.InBufferCount是缓冲区的数据数

GoTo c

End If

End Select

End Sub

Private Sub Option1_Click()

MSComm1.InputMode = comInputModeBinary '接收方式,十六进制

End Sub

Private Sub Option2_Click()

MSComm1.InputMode = comInputModeText '接收方式,字符格式

End Sub

Private Sub Text1_Change()

Text1.SelStart = Len(Text1.Text)

End Sub

VB.NET登陆界面。要验证登录用户名和密码是否正确。登陆后有管理员和普通用户权限判断。管理员只能登录一

将用户名,密码,用户类型存在数据库中,登陆时比较输入的值是否与数据库相同即可。

VB.Net 怎么验证 SQL2008 数据库的ID与密码

基础类库:

Imports Microsoft.VisualBasic

'执行Access语句的封装类。

Public Class AccessExecClass

Private conn As Data.OleDb.OleDbConnection

Private cmd As Data.OleDb.OleDbCommand

'创建类对象,并连接到数据库。

Sub New()

If openAccess Then

Else

msgbox("open Access Fail.")

End If

End Sub

'创建类对象,并连接到数据库。 '输入带目录名称的数据库文件名称:dbFileName,例如:“\DB数据库\企业数据库.aspx”

Sub New(ByVal dbFileName As String)

If OpenAccess(dbFileName) Then

Else

MsgBox("open Access Fail.")

End If

End Sub

Function OpenAccess() As Boolean

OpenAccess = False

'检验用户的帐号密码是否正确

Dim provider As String '= ConfigurationManager.ConnectionStrings("ConnectionString").ProviderName

provider = "Provider=Microsoft.Jet.OLEDB.4.0"

Dim database As String

database = "Data Source=" System.Web.HttpContext.Current.Server.MapPath("\数据库.aspx") ";Persist Security Info=true"

conn = New Data.OleDb.OleDbConnection(provider ";" database)

conn.Open()

OpenAccess = True

End Function

Function OpenAccess(ByVal dbFileName As String) As Boolean

OpenAccess = False

'检验用户的帐号密码是否正确

Dim provider As String '= ConfigurationManager.ConnectionStrings("ConnectionString").ProviderName

provider = "Provider=Microsoft.Jet.OLEDB.4.0"

Dim database As String

database = "Data Source=" System.Web.HttpContext.Current.Server.MapPath(dbFileName) ";Persist Security Info=true"

conn = New Data.OleDb.OleDbConnection(provider ";" database)

conn.Open()

OpenAccess = True

End Function

'关闭数据库。

Sub CloseAccess()

cmd = Nothing

conn.Close()

End Sub

'执行一条Access语句,执行成功就返回True。

Function ExecAccessString(ByVal AccessStr As String) As Boolean

cmd = New Data.OleDb.OleDbCommand(AccessStr, conn)

cmd.ExecuteNonQuery()

'Dim aa As Data.OleDb.OleDbDataReader = cmd.ExecuteReader

ExecAccessString = True

End Function

'返回读取到的数据,注意是用地址传递方式返回

Sub ExecAccessString(ByVal AccessStr As String, ByRef AccessReader As Data.OleDb.OleDbDataReader)

cmd = New Data.OleDb.OleDbCommand(AccessStr, conn)

cmd.ExecuteNonQuery()

AccessReader = cmd.ExecuteReader

End Sub

End Class

登陆代码:

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click

Dim wl As New WebLog '用户登录记录开始,仅对购买了Log 功能的用户,才开放此功能,否则不会实际记录Log

Dim sql As String

Dim aDB As New AccessExecClass

Dim mypw As String

Label1.Visible = False

Label2.Visible = False

Label3.Visible = False

Label4.Visible = False

'没有输入时,不能进行登陆

If TextBox1.Text = "" Then

Label1.Visible = True

Return

End If

If TextBox2.Text = "" Then

Label2.Visible = True

Return

End If

If TextBox3.Text = "" Then

Label3.Visible = True

Return

End If

If TextBox3.Text = TextBox4.Text Then

Else

Label3.Visible = True

Return

End If

Dim iRnd As Integer = Rnd(10) * 100

TextBox3.Text = ""

TextBox4.Text = iRnd.ToString

'Dim iRnd As Integer = Rnd(10) * 100

'注意:此处需要加入防止注入分析,包含'的肯定是特别语句,讲拒绝.

If TextBox1.Text.IndexOf("'") 0 Or TextBox2.Text.IndexOf("'") 0 Then

TextBox1.Text = "不能输入非法字符,将强制清空"

TextBox2.Text = ""

Else

Dim pw As New MD5EnCode(13, 19) ' '2次加密

sql = "select 权限组号,ID , 密码 from 编辑人数据 where 编辑姓名='" + TextBox1.Text + "'"

Dim aa As Data.OleDb.OleDbDataReader '= cmd.ExecuteReader

aDB.ExecAccessString(sql, aa)

If aa.Read() Then

'密码正确()

'sql = aa(2)'需要特别注意:只能单向解密,不能直接转换

mypw = pw.simDeCode(pw.simDeCode(aa(2)))

If TextBox2.Text = mypw Then

Session("LOGIN_Name") = TextBox1.Text '设置登录后的用户名称

Session("Login_Group") = aa(0) 'cmd.ExecuteScalar '设置登录后的权限级别

Session("Login_ID") = aa(1) 'cmd.ToString

'cmd = Nothing

'conn.Close()

Call wl.NewLog("登录", "管理员成功登录")

Response.Redirect("../WebManages/Default.ASPX")

Else

'密码错误()

sql = sql.Replace("'", "【单引号】")

sql = sql.Replace(",", "【逗号】")

Call wl.NewLog("登录", "管理员失败的登录", TextBox1.Text, sql.Replace("""", "【双引号】"), "")

Label4.Visible = True

End If

Else

'密码错误()

sql = sql.Replace("'", "【单引号】")

sql = sql.Replace(",", "【逗号】")

Call wl.NewLog("登录", "管理员失败的登录", TextBox1.Text, sql.Replace("""", "【双引号】"), "")

Label4.Visible = True

End If

End If

End Sub


本文标题:vb.net校验和 vbnet byval
文章网址:http://www.cdkjz.cn/article/doseehp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220