代号中记录中的内容是刊名,刊名记录中的内容是类别(有图片)
Function CreateDataSet(ByVal strSQL As String, ByVal FileName As String, ByVal TableName As String) As DataSetDim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(FileName)
Dim objCmd As New OleDbDataAdapter(strSQL, ConnString)
Dim DS As New DataSet
objCmd.Fill(DS, TableName)
CreateDataSet = DS
End Function
Sub bindlist()
DataGrid1.DataSource = CreateDataSet("select top 5 * from book", "mydb.mdb", "book")
DataGrid1.DataBind()
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then bindlist()
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
bindlist()
End Sub
Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
bindlist()
End Sub
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim dh As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Dim km As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim lb As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Dim kq As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
Dim strSQL As String
strSQL = "update book set 代号=' " & dh & " ',刊名=' " & km & " ',类别=' " & lb & " ',刊期=' " & kq & " 'where " & DataGrid1.DataKeyField & "=" & DataGrid1.DataKeys(e.Item.ItemIndex)
Dim objconn As New OleDbConnection
objconn.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("mydb.mdb")
objconn.Open()
Dim objcmd As New OleDbCommand(strSQL, objconn)
objcmd.ExecuteNonQuery()
DataGrid1.EditItemIndex = -1
bindlist()
End Sub
End Class
[[it] 本帖最后由 twtdd 于 2008-6-15 15:41 编辑 [/it]]