新手提问:关于连接数据库
我的原码如下:
Public Class loginform
Inherits System.Windows.Forms.Form
Public user As String
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents username As System.Windows.Forms.TextBox
Friend WithEvents userpass As System.Windows.Forms.TextBox
Friend WithEvents login As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents msg As System.Windows.Forms.Label
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(loginform))
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.LinkLabel1 = New System.Windows.Forms.LinkLabel
Me.msg = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.login = New System.Windows.Forms.Button
Me.userpass = New System.Windows.Forms.TextBox
Me.username = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.LinkLabel1)
Me.GroupBox1.Controls.Add(Me.msg)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Controls.Add(Me.login)
Me.GroupBox1.Controls.Add(Me.userpass)
Me.GroupBox1.Controls.Add(Me.username)
Me.GroupBox1.Location = New System.Drawing.Point(16, 104)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(264, 144)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "系统登录"
'
'LinkLabel1
'
'
'Label2
'
Me.Label2.ImeMode = System.Windows.Forms.ImeMode.NoControl
Me.Label2.Location = New System.Drawing.Point(40, 56)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(40, 16)
Me.Label2.TabIndex = 4
Me.Label2.Text = "密码:"
'
'Label1
'
Me.Label1.ImeMode = System.Windows.Forms.ImeMode.NoControl
Me.Label1.Location = New System.Drawing.Point(40, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(40, 16)
Me.Label1.TabIndex = 3
Me.Label1.Text = "帐号:"
'
'login
'
Me.login.ImeMode = System.Windows.Forms.ImeMode.NoControl
Me.login.Location = New System.Drawing.Point(80, 88)
Me.login.Name = "login"
Me.login.Size = New System.Drawing.Size(80, 24)
Me.login.TabIndex = 2
Me.login.Text = "登录"
'
'userpass
'
Me.userpass.ImeMode = System.Windows.Forms.ImeMode.NoControl
Me.userpass.Location = New System.Drawing.Point(80, 56)
Me.userpass.Name = "userpass"
Me.userpass.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.userpass.Size = New System.Drawing.Size(150, 21)
Me.userpass.TabIndex = 1
Me.userpass.Text = ""
'
'username
'
Me.username.Location = New System.Drawing.Point(80, 24)
Me.username.Name = "username"
Me.username.Size = New System.Drawing.Size(150, 21)
Me.username.TabIndex = 0
Me.username.Text = ""
'
'
'loginform
'
Me.AcceptButton = Me.login
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(292, 285)
Me.Controls.Add(Me.PictureBox1)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.GroupBox1)
Me.MaximizeBox = False
Me.Name = "loginform"
Me.ShowInTaskbar = False
Me.Text = "koko业务流程管理"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Dim myConnection As New SqlConnection
Private Sub loginform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myConnection = New SqlConnection("uid=sa;password=19781029;database=test_clase;server=(local)")
End Sub
Private Sub login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles login.Click
Hide()
Dim mainform As New mainForm
mainform.Show()
End Sub
End Class
出错提示为:
E:\koko管理\koko\login.vb(174): 未定义类型“SqlConnection”。
E:\koko管理\koko\login.vb(177): 未定义类型“SqlConnection”。
请问如何改