可以不用管它,因为默认值是空,想不出现警告就定义成:dim MsgText as string=""
创新互联网络公司拥有10余年的成都网站开发建设经验,近千家客户的共同信赖。提供成都网站设计、成都做网站、网站开发、网站定制、卖友情链接、建网站、网站搭建、成都响应式网站建设公司、网页设计师打造企业风格,提供周到的售前咨询和贴心的售后服务
Private Function getAccessConnection() As OleDbConnection
'整体思路应该是:连接数据库-运用适配器运行查询词句-将查询结果填充到数据集-以数据集为数据源,在DataGrid中显示。
Dim dbConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=|DataDirectory|\Resources\mag.mdb;Persist Security Info=true"
'连接字符串,Provider,连接引擎,可以死记,OLEDB就用这处,Data Source,设置数据库的位置。
Dim dbConnection As OleDbConnection = New OleDbConnection(dbConnectionString)
Try
dbConnection.Open()
Catch Ex As Exception
’MsgBox(Err.Description)
End Try
Return dbConnection
End Function
private Sub fillDataGridView()
Dim sqlStr As String = "select * from Table"
Dim DataAdapter As New OleDbDataAdapter
Dim dataSet As New DataSet
Dim DataGridView As New DataGridView
Dim dbConnection As OleDbConnection = getAccessConnection()
If dbConnection.State.ToString = "Closed" Then
MsgBox(Chr(13) " access 数据库连接失败 " Chr(13), , "警告")
Exit Sub
End If
DataAdapter.SelectCommand = New OleDbCommand(sqlStr,dbConnection)
'用数据适配器进行查询
Try
DataAdapter.Fill(dataSet,"Table") '将查询结果填充到数据集Dataset,有点像VB中的记录集recordset
DataGridView.DataSource = dataSet.Tables("Table").DefaultView '将数据集的内容在表格中显示出来
Catch Ex As Exception
MsgBox(Err.Description)
Finally
dataSet.Dispose
DataAdapter.Dispose
dbConnection.Close
dbConnection.Dispose
End Try
End Sub
oledbconnection conn=new oledbconnection("连接字符串")
conn.open()
oledbcommand1.connection=conn;
oledb.comandtext= "SELECT 用户, 密码 FROM yonghu where 用户='" Me.TextBox1.Text "' and 密码='" Me.TextBox2.Text "'"
msgbox就可以,很大一部分就是msgbox做的。
或者可以添加一个红色标签,用来提示输入错误并清空密码输入框。