| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 676 人关注过本帖
标题:这个程序代码应该怎样改才可以运行
只看楼主 加入收藏
wingqu
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2006-8-2
收藏
 问题点数:0 回复次数:2 
这个程序代码应该怎样改才可以运行

Dim strTitle As String = "人事管理系统"
Dim myQuery As String
Dim intCmbCnt As Integer
Dim strId As String

Private Sub Initialize()
Me.txtName.Text = ""
Me.txtPassword.Text = ""
Me.cmbPermission.SelectedText = ""
Me.cmbPermission.Text = ""
End Sub

Private Sub Permission_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Initialize()
lstsetting()
Me.txtName.Enabled = False
End Sub

Private Sub lstsetting()
Dim myclsDB As New clsDB
Dim i As Integer
Dim stritem As String
Dim item As ListViewItem
Dim subitem1 As ListViewItem.ListViewSubItem
Dim subitem2 As ListViewItem.ListViewSubItem
Dim subitem3 As ListViewItem.ListViewSubItem
lsvResult.Items.Clear()

myQuery = "select Id,UserName,UserPwd,Class from Operator order by Id"
If myclsDB.DB(myQuery) = False Then
Exit Sub
Else
For i = 0 To myclsDB.dataset.Tables(0).Rows.Count - 1
With myclsDB.dataset.Tables(0)
stritem = .Rows(i).Item(0)
item = New ListViewItem(stritem)
subitem1 = New ListViewItem.ListViewSubItem(item, .Rows(i).Item(1))
subitem2 = New ListViewItem.ListViewSubItem(item, .Rows(i).Item(2))
subitem3 = New ListViewItem.ListViewSubItem(item, .Rows(i).Item(3))
item.SubItems.Add(subitem1)
item.SubItems.Add(subitem2)
item.SubItems.Add(subitem3)
lsvResult.Items.Add(item)

End With
Next
End If
End Sub

'鼠标点击listview控件
Private Sub lsvResult_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lsvResult.MouseUp
If Me.lsvResult.FocusedItem Is Nothing = False Then
Me.chbNew.Checked = False
Me.txtName.Text = Me.lsvResult.FocusedItem.SubItems(1).Text.ToString
Me.txtPassword.Text = Me.lsvResult.FocusedItem.SubItems(3).Text.ToString
Me.cmbPermission.SelectedIndex = CInt(Me.lsvResult.FocusedItem.SubItems(2).Text.ToString)
strId = Me.lsvResult.FocusedItem.Text.ToString

End If
End Sub

'退出程序
Private Sub btnEnd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnd.Click
Me.Close()

End Sub

'删除模块
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
deleteRecord()
End Sub

'删除数据
Private Sub deleteRecord()
Dim myclsdb As New clsDB
With Me.lsvResult
If Me.lsvResult.FocusedItem Is Nothing = False Then
If MsgBox("确实要删除该用户吗?", MsgBoxStyle.Exclamation Or MsgBoxStyle.OKCancel, strTitle) = MsgBoxResult.Cancel Then
Exit Sub
Else
myQuery = "delete from Operator where Id=" & CInt(.FocusedItem.Text.ToString)
If myclsdb.DB(myQuery) = False Then
Exit Sub
Else
lstsetting()
Initialize()

End If
End If
Else
MsgBox("请指定要删除的对象!!", MsgBoxStyle.Exclamation, strTitle)

End If
End With
End Sub

'添加数据
Private Sub insertRecord()
If Me.chbNew.Checked = True And Me.check = True Then
Dim myclsdb As New clsDB
Dim intclass As Integer

Select Case Me.cmbPermission.SelectedIndex
Case 0
intclass = 0
Case 1
intclass = 1
Case 2
intclass = 2
End Select

myQuery = "insert into Operator(UserName,UserPwd,Class) Values('" & Me.txtName.Text.ToString & "','" & Me.txtPassword.Text.ToString & "'," & intclass & ")"
If myclsdb.DB(myQuery) = False Then
Exit Sub
Else
Initialize()
Call lstsetting()

End If
End If
End Sub

'更新数据
Private Sub updateRecord()
If Me.checkupdate = True Then
Dim myclsdb As New clsDB
Dim intclass As Integer

Select Case Me.cmbPermission.SelectedIndex
Case 0
intclass = 0
Case 1
intclass = 1
Case 2
intclass = 2
End Select

myQuery = "update Operator set UserName='" & Me.txtName.Text.Trim() & "',UserPwd='" & Me.txtPassword.Text.Trim() & "',Class=" & intclass & "where Id=" & CInt(strId)
If myclsdb.DB(myQuery) = False Then
Exit Sub
Else
Initialize()
lstsetting()

End If
End If
End Sub

'检查是更新数据还是添加数据
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
If Me.chbNew.Checked = True Then
insertRecord()
Else
updateRecord()
End If
End Sub

'编辑现有数据
Private Function checkupdate() As Boolean
If Me.txtName.Text = "" Then
MsgBox("请选择用户!!", MsgBoxStyle.Exclamation, strTitle)
Me.txtName.Focus()
Return False

End If
If Me.txtPassword.Text = "" Then
MsgBox("请输入密码!!", MsgBoxStyle.Exclamation, strTitle)
Me.txtPassword.Focus()
Return False

End If
If Me.cmbPermission.Text = "" Then
MsgBox("请选择权限!!", MsgBoxStyle.Exclamation, strTitle)
Me.txtPassword.Focus()
Return False

End If
Return True

End Function
'检查输入是否齐全
Private Function check() As Boolean
If Me.txtName.Text = "" Then
MsgBox("请选择用户!!", MsgBoxStyle.Exclamation, strTitle)
Me.txtName.Focus()
Return False

End If
If Me.txtPassword.Text = "" Then
MsgBox("请输入密码!!", MsgBoxStyle.Exclamation, strTitle)
Me.txtPassword.Focus()
Return False

End If
If Me.cmbPermission.Text = "" Then
MsgBox("请选择权限!!", MsgBoxStyle.Exclamation, strTitle)
Me.txtPassword.Focus()
Return False

End If
Dim mycls As New clsDB
myQuery = "select * from Operator where UserName ='" & Me.txtName.Text.ToString & "'"
If mycls.DB(myQuery) = True Then
If mycls.dataset.Tables(0).Rows.Count > 0 Then
MsgBox("该用户名已经存在!", MsgBoxStyle.Exclamation, strTitle)
Return False
Else
Return True

End If
Else
Return False
End If
End Function

'checkbox选择改变时其他控件的变化
Private Sub chbNew_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chbNew.CheckedChanged
If Me.chbNew.Checked = True Then
Me.Initialize()
Me.txtName.Enabled = True
Me.txtName.Focus()
Else
Me.txtName.Enabled = False
End If
End Sub

Private Sub Control_keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtName.KeyDown, txtPassword.KeyDown, btnOK.KeyDown, btnEnd.KeyDown, cmbPermission.KeyDown, chbNew.KeyDown
Dim W_Sendkeys As SendKeys
If e.KeyCode = Keys.Up Or e.KeyCode = Keys.Down Then
e.Handled = True

End If
Select Case e.KeyCode
Case Keys.Return
W_Sendkeys.Send("{TAB}")
Case Keys.Down
W_Sendkeys.Send("{TAB}")
Case Keys.Up
W_Sendkeys.Send("+{TAB}")

End Select
End Sub


上边是小弟查考书上的代码编出来的一个程序
但是不知道为什么运行到上边红色字的那段代码之后就出错啦!!
报错的信息是这样的!
未处理的“System.IndexOutOfRangeException”类型的异常出现在 system.data.dll 中。

其他信息: 无法找到列 3。
请高手教我一下为什么怎样的!



搜索更多相关主题的帖子: 代码 运行 
2006-09-19 20:28
janeju
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2006-3-3
收藏
得分:0 

应该是越界引起的错误,你的ListViewItem.ListViewSubItem(item, .Rows(i).Item(1))应该是ListViewItem.ListViewSubItem(item, .Rows(i).Item(0));ListViewItem.ListViewSubItem(item, .Rows(i).Item(1));ListViewItem.ListViewSubItem(item, .Rows(i).Item(2))。

2006-09-21 10:30
梓风
Rank: 2
等 级:新手上路
威 望:4
帖 子:181
专家分:0
注 册:2006-10-22
收藏
得分:0 

数组下标从0开始


等待相逢
2006-10-24 16:21
快速回复:这个程序代码应该怎样改才可以运行
数据加载中...
 
   



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

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