| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 953 人关注过本帖
标题:[求助]大家帮忙看看这个错误 谢谢·······
只看楼主 加入收藏
VB初学者
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-4-8
收藏
 问题点数:0 回复次数:10 
[求助]大家帮忙看看这个错误 谢谢·······

是登入界面
Imports System.Data.SqlClient.SqlException
Imports System.Data.SqlClient
Public Class login
Inherits System.Windows.Forms.Form

#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 Label1 As System.Windows.Forms.Label
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.TextBox1)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Controls.Add(Me.ComboBox1)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Location = New System.Drawing.Point(40, 32)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(296, 152)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "管理员登陆"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(128, 88)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.TextBox1.Size = New System.Drawing.Size(120, 21)
Me.TextBox1.TabIndex = 3
Me.TextBox1.Text = ""
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(24, 88)
Me.Label2.Name = "Label2"
Me.Label2.TabIndex = 2
Me.Label2.Text = "密码"
'
'ComboBox1
'
Me.ComboBox1.Location = New System.Drawing.Point(128, 32)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(121, 20)
Me.ComboBox1.TabIndex = 1
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(24, 32)
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 0
Me.Label1.Text = "姓名"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(80, 224)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "登陆"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(216, 224)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 2
Me.Button2.Text = "取消"
'
'login
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.BackColor = System.Drawing.SystemColors.ScrollBar
Me.ClientSize = New System.Drawing.Size(394, 287)
Me.ControlBox = False
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.GroupBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "login"
Me.Text = "欢迎登陆"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'将管理员姓名和密码读入到ComboBox1中
' Dim mycon As New SqlConnection(constr)
If mycon.State = ConnectionState.Closed Then
mycon.Open()
End If
Dim myread As SqlDataReader
Dim sqlstr As String = "select Name from Administrator"
Dim mycom As New SqlCommand(sqlstr, mycon)
myread = mycom.ExecuteReader
'从数据阅读器中读数据到ComboBox1中,注意条件的判定
While myread.Read
ComboBox1.Items.Add(myread("Name"))
End While
ComboBox1.SelectedIndex = 0
ad = ComboBox1.Text
ComboBox1.Focus()
mycon.Close()
End Sub

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) = System.Windows.Forms.Keys.Enter Then
Button1.PerformClick()
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'登陆按钮的代码
'首先验证输入数据的合法性
If ComboBox1.Text = "" Or TextBox1.Text = "" Then
MessageBox.Show("用户名或密码不能为空", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If mycon.State = ConnectionState.Closed Then
mycon.Open()
End If
' Dim i As Integer
' Dim t As Integer = 3
' For i = 0 To 2
Dim sqlstr As String = "select Count(*) from Administrator Where Name='" & ComboBox1.SelectedItem & "' and Password='" & TextBox1.Text & "'"
Dim mycom As New SqlCommand(sqlstr, mycon)
If mycom.ExecuteScalar <> 1 Then
' MessageBox.Show("恭喜你登陆成功!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information)
' If t <> i + 1 Then
MessageBox.Show("密码错误!请重新输入!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
TextBox1.Text = ""
ComboBox1.SelectedIndex = 0
Exit Sub

' ElseIf t = i + 1 Then
' MessageBox.Show("你已经输入错误的密码三次,请下次登陆!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
' Me.Close()
' Application.Exit() '这段代码不能执行成功,好好
' End If
' End If
' Next i
Else
MessageBox.Show("恭喜你登陆成功!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Me.Close()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Application.Exit()
End Sub

Private Sub login_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated

End Sub
End Class

运行提示错误:未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中。

其他信息: 系统错误。

大家帮忙看看···

搜索更多相关主题的帖子: 设计 清理 Windows 
2007-04-11 15:13
Kendy123456
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:62
帖 子:2720
专家分:0
注 册:2007-1-3
收藏
得分:0 
提交数据库的时候报错啊
我就不明白了 你把mycon的定义都注释了 为什么还可以编译过去?

2007-04-11 15:39
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
加个 try ...catch..就知道是哪里错了..

飘过~~
2007-04-11 15:54
VB初学者
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-4-8
收藏
得分:0 
以下是引用Kendy123456在2007-4-11 15:39:33的发言:
提交数据库的时候报错啊
我就不明白了 你把mycon的定义都注释了 为什么还可以编译过去?

好像错就停在在mycon.Open()
那里

请问啥意思啊····谢谢

[此贴子已经被作者于2007-4-11 17:29:46编辑过]

2007-04-11 17:23
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 

那就应该是数据库连接有问题..


飘过~~
2007-04-11 17:27
liuminghui
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:2882
专家分:0
注 册:2007-1-26
收藏
得分:0 
system.data.dll 出现了问题?
你的电脑有没有安装数据库,安装好了再看看数据库配置和连接方面的问题

海鸽 is My Lover!!
2007-04-11 17:31
VB初学者
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-4-8
收藏
得分:0 
晕了 数据库我链接了哦····
2007-04-11 17:45
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 

叫你加个 try...catch...你不相信...


飘过~~
2007-04-11 17:48
VB初学者
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-4-8
收藏
得分:0 
以下是引用bygg在2007-4-11 17:48:04的发言:

叫你加个 try...catch...你不相信...

ok
谢谢 指导····

2007-04-11 17:57
VB初学者
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-4-8
收藏
得分:0 
还有个问题
Private Sub mainpro_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "管理员:" & ad & " 登陆"
Dim path As String = "F:\精彩照片\动物\DSCN0516.JPG"
PictureBox1.Image = Image.FromFile(path)
End Sub


换成 在每台机器都能用 咋改 就是调用当前目录下的图片
2007-04-11 18:11
快速回复:[求助]大家帮忙看看这个错误 谢谢·······
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034359 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved