'添加信息
Private Sub TJ_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TJ_Button.Click
Dim myconnection As New SqlClient.SqlConnection(Application("DSN_ZZGL")) : myconnection.Open()
Dim mycommand As SqlClient.SqlCommand
Dim myreader As SqlClient.SqlDataReader
Dim sql As String
Dim sql2 As String
Dim bh As Integer
Dim mc As String
If IsNumeric(BH_text.Text) Then
bh = CInt(BH_text.Text)
Else
Tip1.Text = "栏目编号不能为空,请重新输入!"
bh = 0
Exit Sub
End If
mc = MC_text.Text
If mc = "" Then
Tip1.Text = "栏目名称不能为空,请重新输入!"
Exit Sub
End If
sql = "select * from A01 where A0101=" & bh & " or A0102='" & mc & "'"
mycommand = New SqlClient.SqlCommand(sql, myconnection)
myreader = mycommand.ExecuteReader
If myreader.HasRows Then
Tip1.Text = "添加的内容有重复,请重新输入!"
Exit Sub
Else
myreader.Close()
sql2 = "insert into A01(A0101,A0102) Values(" & bh & ",'" & mc & "')"
mycommand = New SqlClient.SqlCommand(sql2, myconnection)
If mycommand.ExecuteNonQuery = 1 Then
Tip1.Text = "成功添加栏目"
Call showmessage()
End If
End If
mycommand.Dispose()
myconnection.Close()
myconnection.Dispose()
End Sub
'修改信息
Private Sub XG_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XG_Button.Click
Dim myconnection As New SqlClient.SqlConnection(Application("DSN_ZZGL")) : myconnection.Open()
Dim mycommand As SqlClient.SqlCommand
Dim myreader As SqlClient.SqlDataReader
Dim sql As String
Dim bh As Integer
Dim mc As String
If IsNumeric(BH_text.Text) Then
bh = CInt(BH_text.Text)
Else
Tip1.Text = "栏目编号不能为空,请重新输入!"
bh = 0
Exit Sub
End If
mc = MC_text.Text
If mc = "" Then
Tip1.Text = "栏目名称不能为空,请重新输入!"
Exit Sub
End If
sql = "select * from A01 where A0101<> '" & bh & "' and A0102='" & mc & "'"
mycommand = New SqlClient.SqlCommand(sql, myconnection)
myreader = mycommand.ExecuteReader
If myreader.HasRows Then
Tip1.Text = "修改的内容有重复,请重新输入!"
Exit Sub
End If
myreader.Close()
sql = "update A01 set A0102='" & mc & "' where A0101=" & bh & ""
mycommand = New SqlClient.SqlCommand(sql, myconnection)
If mycommand.ExecuteNonQuery = 1 Then
Tip1.Text = "成功修改信息"
Call showmessage()
End If
End Sub
'删除信息
Private Sub SC_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SC_Button.Click
Dim myconnection As New SqlClient.SqlConnection(Application("DSN_ZZGL")) : myconnection.Open()
Dim mycommand As SqlClient.SqlCommand
Dim sql As String
Dim bh As Integer
If IsNumeric(BH_text.Text) Then
bh = CInt(BH_text.Text)
Else
Tip1.Text = "栏目编号不能为空,请重新输入!"
bh = 0
Exit Sub
End If
sql = "delete from A01 where A0101=" & bh & ""
mycommand = New SqlClient.SqlCommand(sql, myconnection)
If mycommand.ExecuteNonQuery = 1 Then
Tip1.Text = "成功删除信息"
Call showmessage()
End If
End Sub
'显示信息
Public Sub showmessage()
Dim myconnection As New SqlClient.SqlConnection(Application("DSN_ZZGL")) : myconnection.Open()
Dim mycommand As SqlClient.SqlCommand
Dim myreader As SqlClient.SqlDataReader
Dim sql As String
sql = "select * from A01"
mycommand = New SqlClient.SqlCommand(sql, myconnection)
myreader = mycommand.ExecuteReader()
DG1.DataSource = myreader
DG1.DataBind()
If myreader.HasRows Then
myreader.Read()
myreader.Close()
mycommand.Dispose()
myconnection.Close()
myconnection.Dispose()
End If