主题:  关于ASP。NET

风花雪夜

职务:普通成员
等级:1
金币:0.0
发贴:53
#12005/3/3 16:11:08
为什么这段代码不能修改最后一个字段啊!

<% @ Page Language="C#" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>

<Script Language="C#" Runat="Server">
OleDbDataReader dr;
public void Page_Load(Object src,EventArgs e)
{
    string MyConnString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("."+"..\\DataBase\\db1.mdb;";    
    OleDbConnection MyConn=new OleDbConnection(MyConnString);
    string strSel="Select * from BookMark";
    OleDbCommand MyComm=new OleDbCommand(strSel,MyConn);
    MyComm.Connection.Open();
    dr=MyComm.ExecuteReader();
    
}
public void Button1(Object sender,EventArgs e)
{    string returnid=Request.QueryString["id"];
    string MyConnString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("."+"..\\DataBase\\db1.mdb;";
    OleDbConnection MyConn = new OleDbConnection(MyConnString);
    string strUpdate = "Update [BookMark] Set SiteName = '" + website.Text + "',URL = '" + introduce.Text + "' Where ID = " + returnid;
    OleDbCommand MyComm=new OleDbCommand(strUpdate,MyConn);
    MyComm.Connection.Open();
    dr=MyComm.ExecuteReader();
    MyConn.Close();
    Response.Redirect("user_member.aspx";

}
</script>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form runat="server">
<table width=500 border=1 cellspacing=0 cellpadding=0 align=center bordercolorlight=#ffffff bordercolordark=#cccccc>
<tr bgcolor=#aaaadd><td>网站名</td><td>网址</td><td>介绍</td><td>删除</td><td>修改</td></tr>
<%
while (dr.Read())
{
%>
<tr>
<td><%=dr["SiteName"].ToString()%></td><td><%=dr["URL"].ToString()%></td><td><%=dr["Comment"].ToString()%></td>
<td><a href=del.aspx?id=<%=dr["id"].ToString()%>>删除</a></td>
<td>
<a href=mod.aspx?id=<%=dr["id"].ToString()%>>修改</a>
</td>
</tr>
<%}
dr.Close();
%>
</table>
<%
string returnid=Request.QueryString["id"];
    string MyConnString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("."+"..\\DataBase\\db1.mdb;";    
    OleDbConnection MyConn=new OleDbConnection(MyConnString);

    string strSel="Select * from BookMark Where ID="+returnid;
    OleDbCommand MyComm=new OleDbCommand(strSel,MyConn);
    MyComm.Connection.Open();
    dr=MyComm.ExecuteReader();
    if(dr.Read())
    {
        website.Text =dr["SiteName"].ToString();
        linkurl.Text=dr["URL"].ToString();
        introduce.Text=dr["Comment"].ToString();
    }
%>
<table width=500 border=1 cellspacing=0 cellpadding=0 align=center bordercolorlight=#ffffff bordercolordark=#cccccc>
<tr>
<td>网站名:</td>
<td><asp:TextBox id="website" runat="server" /></td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td>网&nbsp;&nbsp;&nbsp;&nbsp;址:</td>
<td><asp:TextBox id="linkurl" runat="server" /></td>
<td align="center"><asp:Button Text="修改" onClick="Button1" Runat="Server" /></td>
</tr>
<tr>
<td>介&nbsp;&nbsp;&nbsp;&nbsp;绍:</td>
<td><asp:TextBox id="introduce" runat="server" /></td>
<td align="center"><input type="reset" value="重置"></td>
</tr>
</table>
</form>
</body>
</html>



缺缺

职务:管理员
等级:8
金币:41.0
发贴:9620
#22005/3/3 16:16:44
string strUpdate = "Update [BookMark] Set SiteName = '" + website.Text + "',URL = '" + introduce.Text + "' Where ID = " + returnid;

先看明白这句



风花雪夜

职务:普通成员
等级:1
金币:0.0
发贴:53
#32005/3/3 16:40:24
谢谢提示!我是初学。NET 没注意这些问题。不知如何去检查这些问题,

现在问题已解决。

你会JSP吗?你知道在网上不用数据源链接数据库,应该怎样去链接呀!