selcmd 到底什么 为什么我用vs2015打出来有错误

qq_37001113 2016-12-11 01:34:12
完整程序,人后 selcmd1 secmd2 下面 有一个
Handles clause requires a WithEvents variable difined in the containing or one of its base types
书上用的程序是vB.net
我用的事vs2015

Imports System.Data.SqlClient
Public Class edstudent
Public mydv As New DataView()
Dim mytable As DataTable
Dim mytable1 As DataTable
Dim condstr As String = ""

Private Sub edstudent_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
mytable = Dbop.Exesql("SELECT * FROM student")
mydv = mytable.DefaultView
DataGridView1.ReadOnly = True
DataGridView1.DataSource = mydv
DataGridView1.GridColor = Color.RoyalBlue
DataGridView1.ScrollBars = ScrollBars.Vertical
DataGridView1.ColumnHeadersDefaultCellStyle.Font = New Font("隶书", 10)
DataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single
DataGridView1.Columns(0).HeaderText = "学 号"
DataGridView1.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(1).HeaderText = "姓 名"
DataGridView1.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(2).HeaderText = "性 别"
DataGridView1.Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(3).HeaderText = "出生日期"
DataGridView1.Columns(3).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
DataGridView1.Columns(4).HeaderText = "班 号"
DataGridView1.Columns(4).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
mytable1 = Dbop.Exesql("SELECT distinct sclass FROM student")
ComboBox2.DataSource = mytable1
ComboBox2.DisplayMember = "sclass"
ComboBox1.Items.Add("男") : ComboBox1.Items.Add("女")
TextBox1.Text = "" : TextBox2.Text = ""
TextBox3.Text = "" : ComboBox1.Text = ""
ComboBox2.Text = ""
Call enbutton()


End Sub

Private Sub Button4_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()

End Sub
Private Sub selcmd1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles selcmd1.click
condstr = ""
If TextBox1.Text <> "" Then
condstr = "sno Like '" & TextBox1.Text & "%'"

End If
If TextBox2.Text <> "" Then
If condstr <> "" Then
condstr = condstr & "AND sname like'" & TextBox2.Text & "%'"
Else
condstr = "sname Like '" & TextBox2.Text & "%'"
End If
End If
If TextBox3.Text <> "" Then
If IsDate(TextBox3.Text) Then
If condstr <> "" Then
condstr = condstr & " AND sbirthday='" & TextBox3.Text & "'"
Else
condstr = "sbirthday='" & TextBox3.Text & "'"
End If
Else
MsgBox("输入学生信息不正确", MsgBoxStyle.OkOnly, "信息提示")
Exit Sub

End If

End If
If ComboBox1.Text <> "" Then
If condstr <> "" Then
condstr = condstr & "AND ssex ='" & ComboBox1.Text & "'"
Else
condstr = "sname= '" & ComboBox1.Text & "'"
End If
End If
If ComboBox2.Text <> "" Then
If condstr <> "" Then
condstr = condstr & "AND sclass = '" & ComboBox2.Text & "'"
Else
condstr = "sclass = '" & ComboBox2.Text & "'"
End If
End If
mydv.RowFilter = condstr
Call enbutton


End Sub
Private Sub selcmd2_click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles selcmd2.click
TextBox1.Text = "" : TextBox2.Text = ""
TextBox3.Text = "" : ComboBox1.Text = ""
ComboBox2.Text = ""
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.RowIndex >= 0 And e.RowIndex < DataGridView1.RowCount - 1 Then
no = DataGridView1.Rows(e.RowIndex).Cells(0).Value
Else
no = ""
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
flag = 1
edstudent1.ShowDialog()
mytable = Dbop.Exesql("SELECT * FROM student")
mydv = mytable.DefaultView
DataGridView1.DataSource = mydv
mytable1 = Dbop.Exesql("SELECT distinct sclass FROM student")
ComboBox2.DataSource = mytable1
ComboBox2.DisplayMember = "sclass"
ComboBox2.Text = ""
mydv.RowFilter = condstr
Call enbutton()


End Sub

Private Sub Button2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button2.Click
flag = 2
If no <> "" Then

edstudent1.ShowDialog()
mytable = Dbop.Exesql("SELECT * FROM student")
mydv = mytable.DefaultView
DataGridView1.DataSource = mydv
mytable1 = Dbop.Exesql("SELECT distinct sclass FROM student")
ComboBox2.DataSource = mytable1
ComboBox2.DisplayMember = "sclass"
ComboBox2.Text = ""
mydv.RowFilter = condstr
Else
MsgBox("先选择要修改的学生记录", MsgBoxStyle.OkOnly, "信息提示")

End If

End Sub

Private Sub Button3_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button3.Click
Dim mysql As String
flag = 3
If no <> "" Then
If MsgBox("真的要删除学号为" & Trim(no) & "的学生记录?",
MsgBoxStyle.YesNo, "确认删除") = MsgBoxResult.Yes Then
flag = 3
mysql = "DELETE student WHERE sno ='" & no & "'"
mytable1 = Dbop.Exesql(mysql)

mytable = Dbop.Exesql("SELECT * FROM student")
mydv = mytable.DefaultView
DataGridView1.DataSource = mydv
mytable1 = Dbop.Exesql("SELECT distinct sclass FROM student")
ComboBox2.DataSource = mytable1
ComboBox2.DisplayMember = "sclass"
ComboBox2.Text = ""
mydv.RowFilter = condstr
Call enbutton()

End If
Else
MsgBox("先选择删除的学生记录", MsgBoxStyle.OkOnly, "信息提示")

End If

End Sub
Private Sub enbutton()
TextBox4.Text = mydv.Count
If mydv.Count = 0 Then
Button2.Enabled = False
Button3.Enabled = False
no = ""
Else
Button2.Enabled = True
Button2.Enabled = True
no = mydv.Item(0)("sno")

End If
End Sub
End Class
...全文
442 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧