.NET+SQL Server2000图书管理系统 第4页
登陆成功后:
点击删除后:
再次查询时:
Imports System.Data.SqlClient
Public Class delete
Inherits System.Web.UI.Page
Dim myconn As SqlConnection
Private connectingstring As String
Private ds As DataSet
Private myAdapter As SqlDataAdapter
Private myCmd As SqlCommand
Public Sub BindDBGrd(ByVal sqlstr As String, ByVal myDBGrd As DataGrid)
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
Fill(sqlstr)
myDBGrd.DataSource = ds.Tables(0).DefaultView
myDBGrd.DataBind()
End Sub
Public Sub Fill(ByVal sqlstr As String)
myAdapter = New SqlDataAdapter(sqlstr, myConn)
ds = New DataSet
myAdapter.Fill(ds)
End Sub
Public Sub BindDBGrd(ByVal sqlstr As String, ByVal myDBGrd As DataGrid, ByVal SortExp As Object)
If myconn.State = ConnectionState.Closed Then
myconn.Open()
End If
Fill(sqlstr)
Dim dv As DataView = ds.Tables(0).DefaultView
dv.Sort = SortExp
myDBGrd.DataSource = dv
myDBGrd.DataBind()
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
connectingstring = "data source=(local);Database=library;uid=sa;pwd=123456;"
myconn = New SqlConnection(connectingstring)
If Not IsPostBack Then
Dim sqlstr As String = "select * from bookinfo "
BindDBGrd(sqlstr, DataGrid1)
Dim ds As DataSet = New DataSet
End If
End Sub
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
Dim sql As String
Dim getdata As SqlDataReader
Dim mycmd As SqlCommand
Dim uid As String = DataGrid1.Items(e.Item.ItemIndex).Cells(0).Text
sql = "delete from bookinfo where bookid='" + uid + "'"
mycmd = New SqlCommand(sql, myconn)
myconn.Open()
mycmd.ExecuteNonQuery()
myconn.Close()
mycmd.Dispose()
Response.Write("<script>javascript:alert('删除成功!!!');</script>")
End Sub
End Class
点击用户登录后:
Imports System.Data.SqlClient
Imports System.IO
Public Class WebForm1
Inherits System.Web.UI.Page
Private connectingstring As String
Private myConn As SqlConnection
Private ds As DataSet
Private myAdapter As SqlDataAdapter
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Private myCmd As SqlCommand
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
connectingstring = "data source=(local);Database=library;uid=sa;pwd=123456;"
myConn = New SqlConnection(connectingstring)
End Sub
Public Function CheckUserberInfo(ByVal Userstr As String, ByVal Pwdstr As String) As Integer
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
Dim sqlstr As String
If Pwdstr = "" Then
sqlstr = "select * from Users where UserID='" + Userstr.Trim + "' and Pass is null"
Else
sqlstr = "select * from Users where UserID='" + Userstr.Trim + "' and Pass='" + Pwdstr + "'"
End If
Fill(sqlstr)
If ds.Tables(0).Rows.Count = 0 Then
Close()
Return -1
End If
ds.Clear()
Close()
Return 1
End Function
Public Sub Open()
myConn.Open()
End Sub
Public Sub Close()
myConn.Close()
End Sub
Public Sub Fill(ByVal sqlstr As String)
myAdapter = New SqlDataAdapter(sqlstr, myConn)
ds = New DataSet
myAdapter.Fill(ds)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If CheckUserberInfo(TextBox1.Text, TextBox2.Text) = 1 Then
Session("UserID") = TextBox1.Text.ToString
Response.Redirect("userlist.aspx")
Else
Response.Write("<script>javascript:alert('登陆失败!!!');</script>")
Response.Write("javascript:window.location='Login.aspx'")
End If
End Sub
End Class
登录成功后:
Imports System.Data.SqlClient
Public Class userlist
Inherits System.Web.UI.Page
Dim myConn As SqlConnection
Private myCmd As SqlCommand
Private connectingstring As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
connectingstring = "data source=(local);Database=library;uid=sa;pwd=123456;"
myConn = New SqlConnection(connectingstring)
If Session("UserID") = "" Then
Response.Redirect("Login.aspx")
Else
LoadUserInfo(Session("UserID"))
End If
End Sub
Public Function ExecReaderSql(ByVal sqlstr As String) As SqlDataReader
If myConn.State = ConnectionState.Closed Then
myConn.Open()
End If
myCmd = New SqlCommand(sqlstr, myConn)
Dim reader As SqlDataReader
reader = myCmd.ExecuteReader
myCmd.Dispose()
Return reader
End Function
Public Sub LoadUserInfo(ByVal UserID As String)
Dim sqlstr As String = "select * from Users where UserID='" + UserID + "'"
Dim myreader As SqlDataReader = ExecReaderSql(sqlstr)
If myreader.Read Then
txtUserID.Text = myreader("UserID")
txtName.Text = myreader("username")
txtphone.Text = myreader("Phone")
txtaddress.Text = myreader("address")
txtEMail.Text = myreader("EMail")
End If
myConn.Close()
End Sub
End Class