人类爱我吧:asp.net查询问题,在线等

来源:百度文库 编辑:高考问答 时间:2024/04/29 07:53:37
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim a As String = CType(e.Item.Cells(0).Controls(0), TextBox).Text
Dim b As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim c As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Dim d As DateTime = Convert.ToDateTime(CType(e.Item.Cells(4).Controls(0), TextBox).Text)
Dim f As String = CType(e.Item.Cells(5).Controls(0), TextBox).Text
Dim g As String = CType(e.Item.Cells(6).Controls(0), TextBox).Text
Dim mysql As String
mysql = "update cpxs set 必要说明='" + a + "' ,变电站='" + b + "',产品名称='" + c + "',发货日期='" + d + "',随机资料='" + f + "',资料编号='" + g + "' where 资料编号='" + e.Item.Cells(6).Text + "'"
Dim searchcmd1 As New OleDbCommand
searchcmd1.CommandText = mysql
searchcmd1.Connection = conn
conn.Open()
searchcmd1.ExecuteNonQuery()
Response.Write("<script>alert('数据修改成功!');</script>")
DataGrid1.EditItemIndex = -1
getfull()
End Sub
不能更新,怎么回事,谢谢

where 资料编号='" + e.Item.Cells(6).Text + "'" 这就不对.看看这个.你的代码不全.没法看呀.

<%@ import namespace="system.data" %>
<%@ import namespace="system.data.oledb" %>
<script language=vb runat=server>
sub bindlist()
dim conn as string = "provider=microsoft.jet.oledb.4.0;data source = " & server.mappath("ch17\Grades.mdb")
dim sql as string ="Select * From 成绩单"
dim da as new oledbdataadapter(sql,conn)
dim ds as new dataset()
da.fill(ds,"chwu")
dim mytable as datatable = ds.tables("chwu")
mydatagrid.datasource = mytable
mydatagrid.databind()
end sub

sub page_load(sender as object , e as eventargs)
if not ispostback then bindlist()
end sub

sub datagrid_editcommand(sender as object , e as datagridcommandeventargs)
mydatagrid.edititemindex = e.item.itemindex
bindlist()
end sub

sub datagrid_cancelcommand(sender as object , e as datagridcommandeventargs)
mydatagrid.edititemindex = - 1
bindlist()
end sub

sub datagrid_updatecommand(sender as object , e as datagridcommandeventargs)
dim name as string = ctype(e.item.cells(1).controls(0),textbox).text
dim aa as string = ctype(e.item.cells(2).controls(0),textbox).text
dim bb as string = ctype(e.item.cells(3).controls(0),textbox).text
dim strsql as string
strsql = "update 成绩单 set 姓名 = '" & name & "' , 会计 = '" & aa & "',统计 = '" & bb & "' where " & mydatagrid.datakeyfield & " = '" & mydatagrid.datakeys(e.item.itemindex) & "'"
dim objconn as new oledbconnection("provider=microsoft.jet.oledb.4.0;data source = " & server.mappath("ch17\Grades.mdb"))
objconn.open()
dim objcomm as new oledbcommand(strsql,objconn)
objcomm.executenonquery
mydatagrid.edititemindex = -1
bindlist()
end sub
</script>
<html>
<body>
<h1 align=center>成绩表</h1>
<form runat=server>
<asp:datagrid runat=server id=mydatagrid autogeneratecolumns=false horizontalalign=center datakeyfield="学号" width=800
oneditcommand="datagrid_editcommand" oncancelcommand="datagrid_cancelcommand" onupdatecommand="datagrid_updatecommand">
<headerstyle font-size=small forecolor=#ffffcc font-bold=true backcolor=#990000 horizontalalign=center />
<itemstyle font-size=x-small forecolor=#330099 />
<columns>
<asp:templatecolumn headertext=学号>
<itemtemplate>
<%# container.dataitem("学号") %>
</itemtemplate>
<edititemtemplate>
<%# container.dataitem("学号") %>
</edititemtemplate>
</asp:templatecolumn>
<asp:boundcolumn headertext=姓名 datafield=学号 />

<asp:boundcolumn headertext=会计 datafield=会计 />
<asp:boundcolumn headertext=统计 datafield=统计 />
<asp:editcommandcolumn headertext=功能 edittext=编辑 canceltext=取消 updatetext=更新 itemstyle-horizontalalign=center />
</columns>
</asp:datagrid>
</form>
</body></html>