|
我照抄的,帮看下错在哪:
Public Class pkinds_mad
Inherits System.Web.UI.Page
Dim myconstr As String = ConfigurationSettings.AppSettings("constr") & Server.MapPath(".") & ConfigurationSettings.AppSettings("dbs")
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
Protected WithEvents OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand
Protected WithEvents OleDbUpdateCommand1 As System.Data.OleDb.OleDbCommand
Protected WithEvents OleDbDeleteCommand1 As System.Data.OleDb.OleDbCommand
Protected WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
Protected WithEvents DataSet11 As minishop1.DataSet1
Dim mycon As OleDb.OleDbConnection = New OleDb.OleDbConnection(myconstr)
End Sub
'为datagrid绑定数据的过程
Sub BindGrid()
Dim mycmd As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("select id,pkinds from tab_pkinds", mycon)
Dim dt As Data.DataSet = New Data.DataSet
mycmd.Fill(dt)
Dim dv As Data.DataView = New Data.DataView(dt.Tables(0))
DataGrid1.DataSource = dv
DataGrid1.DataBind()
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
Me.OleDbDataAdapter1.Fill(DataSet11)
DataGrid1.DataBind()
If Not IsPostBack Then
BindGrid() '数据加载函数
End If
End Sub
'更新事件过程
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim mysql As String
Dim mycmd As OleDb.OleDbCommand
Dim id As Integer = e.Item.Cells(0).Text '获取激活行的第一单元格的文本
Dim Txt As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text.ToString '将单元格转换为textbox控件,再获取他的文本
mysql = "UPDATE tab_pkinds SET tab_pkinds.pkinds = '" + Txt + "' WHERE id=" & id
Response.Write(Txt)
mycon.Open()
mycmd = New OleDb.OleDbCommand(mysql, mycon)
mycmd.ExecuteNonQuery()
mycon.Close()
DataGrid1.EditItemIndex = -1
BindGrid()
End Sub |
|