主题:这些代码是连接服务器的谁能给我解释一下啊
Private Sub btnDbConn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDbConn.Click
Dim succ As Boolean = False
If txtServer.Text = "" Then
MsgBox("请输入服务器名")
ElseIf txtDatabase.Text = "" Then
MsgBox("请输入数据库名")
End If
'如果用户名跟密码都为空,则尝试用WINDOWS的集成安全性连接数据库
If txtUsername.Text = "" And txtPassword.Text = "" Then
If OleConn.SqlConnection(txtServer.Text, txtDatabase.Text) Then
succ = True
End If
Else
If OleConn.SqlConnection(txtServer.Text, txtDatabase.Text, txtUsername.Text, txtPassword.Text) Then
succ = True
End If
End If
If succ Then
Server = txtServer.Text
Database = txtDatabase.Text
Username = txtUsername.Text
Password = txtPassword.Text
'保存登录设置到注册表
SaveSetting("student", "config", "server", Server)
SaveSetting("student", "config", "database", Database)
SaveSetting("student", "config", "username", Username)
SaveSetting("student", "config", "password", Password)
'控制返回到主界面
btnDefault.PerformClick()
End If
End Sub
Private Sub frmDbConn_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'从注册表读连接设置
Server = GetSetting("student", "config", "server")
Database = GetSetting("student", "config", "database")
Username = GetSetting("student", "config", "username")
Password = GetSetting("student", "config", "password")
txtServer.Text = Server
txtDatabase.Text = Database
txtUsername.Text = Username
txtPassword.Text = Password
End Sub
Dim succ As Boolean = False
If txtServer.Text = "" Then
MsgBox("请输入服务器名")
ElseIf txtDatabase.Text = "" Then
MsgBox("请输入数据库名")
End If
'如果用户名跟密码都为空,则尝试用WINDOWS的集成安全性连接数据库
If txtUsername.Text = "" And txtPassword.Text = "" Then
If OleConn.SqlConnection(txtServer.Text, txtDatabase.Text) Then
succ = True
End If
Else
If OleConn.SqlConnection(txtServer.Text, txtDatabase.Text, txtUsername.Text, txtPassword.Text) Then
succ = True
End If
End If
If succ Then
Server = txtServer.Text
Database = txtDatabase.Text
Username = txtUsername.Text
Password = txtPassword.Text
'保存登录设置到注册表
SaveSetting("student", "config", "server", Server)
SaveSetting("student", "config", "database", Database)
SaveSetting("student", "config", "username", Username)
SaveSetting("student", "config", "password", Password)
'控制返回到主界面
btnDefault.PerformClick()
End If
End Sub
Private Sub frmDbConn_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'从注册表读连接设置
Server = GetSetting("student", "config", "server")
Database = GetSetting("student", "config", "database")
Username = GetSetting("student", "config", "username")
Password = GetSetting("student", "config", "password")
txtServer.Text = Server
txtDatabase.Text = Database
txtUsername.Text = Username
txtPassword.Text = Password
End Sub