BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / dot-net / #3030同步于 2011/6/2
该镜像源已超过 30 天没有更新,可能在源站已被删除。
dotNET机器人发帖

【求助】问个C#+ASP.NET中将数据返回SQL SERVER数据库的问题

Imagine
2011/6/2镜像同步4 回复
做的图书馆管理信息系统,网上下载的一个完好的系统修改的。增加续借功能时出了问题。 设计为触发续借则将借阅时间更新为当前时间,应还时间随之更改。目前是更改后的值无法保存回数据库。 输出值确定是正确更新了的。代码如下,前两个Response.Write的内容能正常输出,但是最后一个Response.Write输出为0.SQL语句写入SQLserver查询是能正常运行的。现在不知道是哪里的问题了。 protected void gvBorrowBook_RowUpdating(object sender, GridViewUpdateEventArgs e) { Response.Write("<script>alert('现在时间为"+Convert.ToDateTime(DateTime.Now.ToShortDateString())+" ')</script>"); borrowandbackmanage.ID = borrowandbackmanage.GetBorrowBookID(); borrowandbackmanage.BorrowTime = Convert.ToDateTime(DateTime.Now.ToShortDateString()); int days = Convert.ToInt32(btypemanage.FindBTypeByName(btypemanage, "tb_booktype").Tables[0].Rows[0][2].ToString()); TimeSpan tspan = TimeSpan.FromDays((double)days); borrowandbackmanage.YGBackTime = borrowandbackmanage.BorrowTime + tspan; Response.Write("<script>alert('续借后应还时间为" + (borrowandbackmanage.BorrowTime + tspan) + " ')</script>"); borrowandbackmanage.UpdateDelayBorrow(borrowandbackmanage; Response.Write("<script>alert('"+borrowandbackmanage.UpdateDelayBorrow(borrowandbackmanage)+"')</script>"); gvBRBookBind(); } UpdateDelayBorrow函数写在公共类里面的,代码为: public int UpdateDelayBorrow(BorrowandBackManage borrowandbackmanage) { SqlParameter[] prams = { data.MakeInParam ("@id",SqlDbType.VarChar, 30, borrowandbackmanage.ID), data.MakeInParam ("@borrowtime",SqlDbType.DateTime, 8, borrowandbackmanage.BorrowTime ), data.MakeInParam ("@ygbacktime",SqlDbType.DateTime, 8, borrowandbackmanage.YGBackTime ), }; return (data.RunProc("update tb_borrowandback set borrowtime=@borrowtime,ygbacktime=@ygbacktime where id=@id", prams)); }
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
wangjianzhou机器人#1 · 2011/6/2
这位同学,上次给你答过了,怎么不看你下,ASP.NET有严格页面生命周期,你的事件有顺序。 protected void gvBorrowBook_RowUpdating(object sender, GridViewUpdateEventArgs e) { &#8195;&#8195;&#8195;&#8195; if (!Page.IsPostBack) //加上这个页面不是第一次回传服务器 &#8195;&#8195;&#8195;&#8195; { ……你的那一堆代码 &#8195;&#8195;&#8195;&#8195;&#8195;&#8195; databind(); &#8195;&#8195;&#8195;&#8195; } }
Imagine机器人#2 · 2011/6/3
【 在 wangjianzhou 的大作中提到: 】 : 这位同学,上次给你答过了,怎么不看你下,ASP.NET有严格页面生命周期,你的事件有顺序。 : protected void gvBorrowBook_RowUpdating(object sender, GridViewUpdateEventArgs e) : { : ................... 这个加了的。还是不行呢~
wangjianzhou机器人#3 · 2011/6/3
【 在 Imagine 的大作中提到: 】 : : 这位同学,上次给你答过了,怎么不看你下,ASP.NET有严格页面生命周期,你的事件有顺序。 : : protected void gvBorrowBook_RowUpdating(object sender, GridViewUpdateEventArgs e) : : { : ................... 别用富控件自带的命令,自己用ADO.NET写一个,就十几行代码。 页面的代码 <asp:GridView ID="GridView1" …… OnRowCommand="gvBorrowBook_RowUpdating" Runat="Server"> <Columns> <asp:ButtonField Text="续借" CommandName="Borrow"/> ……其它绑定 </Columns> </asp:GridView> CodeBehind代码 protected void gvBorrowBook_RowUpdating(object sender, GridViewCommandEventArgs e) { if(e.CommandName=="Borrow") { int index = Int32.Parse((string)e.CommandArgument); SqlConnection con = new SqlConnection("连接字符串"); SqlCommand cmd = new SqlCommand("UPDATE 表名 SET borrowtime=@borrowtime,ygbacktime=@ygbacktime WHERE id=@id", con); cmd.Parameters.AddWithValue("@id", (int)GridView1.DataKeys[index].Values ["id"]); cmd.Parameters.AddWithValue("@ygbacktime", 归还时间); cmd.Parameters.AddWithValue("@borrowtime", DateTime.Now); using (con) { con.Open(); Object re = cmd.ExecuteScalar(); if (re != null) { Response.Write("<script>alert('续借后应还时间为" + (还书时间) + " ')</script>"); } } } } 有问题站内我
ahomer机器人#4 · 2011/6/3
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword; 你确定数据库连接中的User Id 有修改数据库的权限吗?