高分求简单实例
100分求一段简单的数据库操作代码:包括查看,修改,添加,删除等操作!我用的是VB.net。数据库SQL,有相关实例最好,有答案马上给分。。谢谢!!
------解决方案-------------------- '添加信息
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
mycommand.Dispose()
myconnection.Close()
myconnection.Dispose()