连接未关闭是连线.open().. visual basic 2008 express edition中的警告 [英] the connection was not closed is the warning in the line connect.open().. visual basic 2008 express edition
本文介绍了连接未关闭是连线.open().. visual basic 2008 express edition中的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Private Sub txtusername_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtusername.TextChanged
username = txtusername.Text
connect.Open()
ds.Clear()
da = New OleDb.OleDbDataAdapter("SELECT * FROM tbluser", connect)
da.Fill(ds, "tbluser")
Dim dv As New DataView(ds.Tables("tbluser"))
dv.RowFilter = "username= '" & username & "'"
DataGridView1.DataSource = dv
connect.Close()
End Sub
推荐答案
将此替换为con.open()和con.Close()
Replace this instead of con.open() and con.Close()
if(con.state==ConnectionState.Closed)
{
con.open();
}
if(con.state==ConnectionState.Open)
{
con.Close();
}
错误,因为您的连接未关闭但您正在尝试打开它。
The Error because your Connection is not closed but you are trying to open it.
DataAdapter
自动打开和关闭连接。无需明确打开连接。
参考 - OleDbDataAdapter构造函数(String,OleDbConnection) [ ^ ]
DataAdapter
automatically opens and closes the connection. No need to explicitly open the connection.
Reference - OleDbDataAdapter Constructor (String, OleDbConnection)[^]
这篇关于连接未关闭是连线.open().. visual basic 2008 express edition中的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文