设置ID输入框的Valiating事件,假定ID是字符型: Dim vl as String =e.Form.Controls("ID输入框").Value If vl = "" Then MessageBox.show("请输入ID") Else Dim cmd As New SQLCommand Dim dt As DataTable cmd.C cmd.CommandText = "SELECT Name From {Users} Where ID = '" & vl & "'" dt = cmd.ExecuteReader() if dt.DtaRows.Count = 0 Then MessageBox.show("用户ID不存在!","提示") Else e.Form.Controls("用户名输入框").Value = dt.Datarows(0)("Name") End if End if 大概如此,具体自行调整。
|