主题:急!急!求救!在学习ASP.NET中遇到了问题
本人在不久前做了下面一个页面。在SQL Server 2000中新建了一个数据库名叫:网上销售系统,在该数据库中建了一张名为:test的表,里面有name,sex两个字段。当然里面有一条记录。当将该表的该记录从数据库中查询出,放入dataset()中,便将dataset()中的值输出到页面相应的文本框。但当在该页面中的文本框中修改之前的数据,然后单击页面中的确定按钮,确定按钮有一事件,我想利用该事件修改test表中的值,但却发现test表并没有改变。请问这是什么原因呢?
各位ASP.NET 高手,请帮帮忙,本人急用呀!!谢谢大家!!
下面是相关的代码!!(我是用VB写的)
<%@ Import Namespace="System.Data" %>
<%@ import namespace="system.data.sqlclient" %>
<script Language="vb" runat="server">
function selectsql(str as string) as dataset
dim conn as new sqlconnection("server=localhost; Database=网上销售系统;uid=sa;pwd=12")
dim cmd as new sqlcommand(str,conn)
dim adp as new sqldataadapter(cmd)
Dim customers As DataSet = New DataSet
adp.fill(customers,"buy")
return customers
end function
Sub Page_Load(Sender As Object, E As EventArgs)
dim str as string
str="select* from test"
dim ods as new dataset()
ods=selectsql(str)
dim odr as datarow
odr=ods.tables(0).rows(0)
name.text=trim(odr.itemarray(0).tostring())
sex.text=trim(odr.itemarray(1).tostring())
end sub
sub revisesql(str as string)
dim conn as new sqlconnection("server=localhost; Database=网上销售系统;uid=sa;pwd=12")
dim cmd as new sqlcommand(str, conn)
conn.open()
cmd.executenonquery()
conn.close
end sub
sub enter_click(sender as object,e as eventargs)
dim str as string
str="update test set name='" & name.text & "',sex='" & sex.text & "'"
call revisesql(str)
end sub
</script>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>购买商品</title>
</head>
<body>
<center>
<form runat="server">
<TABLE>
<TR>
<TD>姓名:</TD>
<TD><asp:textbox id ="name" runat="server"/>
<asp:requiredfieldvalidator id="require1" controltovalidate="name" errormessage="必须输入姓名" runat="server"/></TD>
</TR>
<TR>
<TD>姓别:</TD>
<TD><asp:textbox id ="sex" runat="server"/>
<asp:requiredfieldvalidator id="require2" controltovalidate="sex" errormessage="必须输入姓别" runat="server"/></TD>
</TR>
</TABLE>
<asp:button id="enter1" text="确定" onclick="enter_click" runat="server" />
</center>
</form>
</body>
</html>[em10][em10][em10]