请帮我看看,不管是否正常连接,为何下面代码的变量bConnect 一直为 True ?
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickWith st
.ser_name = TextBox1.Text
.dat_name = TextBox2.Text
.use_name = TextBox3.Text
.pwd_id = TextBox4.Text
End With
constring = "Data Source=" + Trim(TextBox1.Text)
constring &= ";Initial Catalog=" + Trim(TextBox2.Text)
constring &= ";Persist Security Info=True;User ID=" + Trim(TextBox3.Text)
constring &= ";Password=" + Trim(TextBox4.Text)
' MsgBox(constring)
Dim objConnection As New SqlConnection(constring)
Dim objDataAdapter As SqlDataAdapter = New SqlDataAdapter()
Dim objDataSet As DataSet = New DataSet()
Try
objDataAdapter.SelectCommand = New SqlCommand
objDataAdapter.SelectCommand.Connection = objConnection
objDataAdapter. = "select 姓名,密码,权限 from idpass"
objDataAdapter. = CommandType.Text
objConnection.Open()
objDataAdapter.Fill(objDataSet, "idpass")
Catch ex As Exception
MsgBox("本软件与数据库服务器无法正常连接" + vbCrLf + "请检查与服务器的连接是否正常" + vbCrLf + vbCrLf + "请检查您输入的参数是否正确?" + vbCrLf + "请修改正确后再试...... ", 64, "连接错误提示")
bConnect = False
Finally
bConnect = True
End Try
objConnection.Close()
objDataAdapter = Nothing
objConnection = Nothing
If bConnect = True Then
ss = FreeFile()
FileOpen(ss, wjm, OpenMode.Random, , , Len(st))
FilePut(ss, st, 1)
FileClose(ss)
MsgBox("参数正确,已经保存成功!", 64, "提示")
End If
End Sub