怎么断开SQL语句中的连接啊?那个好心人帮看一下?
Dim conn As New SqlConnection( "data source=127.0.0.1;initial catalog=项目信息管理系统;User id=text; password=1111; ")
conn.Open()
Dim sql As String
sql = "select * from Users where user_id= ' " & yhbh.Text & " ' "
Dim cmd As New SqlCommand(sql, conn)
conn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.Read = True Then
MsgBox( "该用户已经存在,请你重新添加! ")
conn.Close()
Else
Dim strsql As String
strsql = " insert into Users(User_id,Name,Password,branch,Tell,E_mail)values( " & yhbh.Text & ", ' " & yhm.Text & " ', ' " & yhmm.Text & " ', ' " & szbm.Text & " ', ' " & yhdh.Text & " ', ' " & yhyx.Text & " ') "
cmd.ExecuteNonQuery()
conn.Close()
MsgBox( "用户信息添加成功! ")
End If
End If
------解决方案--------------------再加一个dr.Close()
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.Read = True Then
MsgBox( "该用户已经存在,请你重新添加! ")
dr.Close() '再加一个这个吧
conn.Close()
Else
Dim strsql As String
strsql = " insert into Users(User_id,Name,Password,branch,Tell,E_m