我的更新内容包括:Id,Code,Name,Type,Publisher,PurDate,Comment。为什么我的更新不能实现:要不就是没改,要不就是为空。。请专家帮我诊断!谢谢!我的毕业设计其他全部完成了,就差这个更新功能了,急人啊!!拜托各位大侠了,小弟拜谢!  
 
程序如下:  
 
       Private  Sub  dgbook_UpdateCommand(ByVal  source  As  Object,  ByVal  e  As  System.Web.UI.WebControls.DataGridCommandEventArgs)  Handles  dgbook.UpdateCommand  
               Dim  ds  As  DataSet  =  bookInfo.GetBookInfo  
               Dim  Id  As  Integer  
               Dim  Code  As  String  
               Dim  Name  As  String  
               Dim  Type  As  String  
               Dim  Publisher  As  String  
               Dim  PurDate  As  String  
               Dim  Comment  As  String  
               'execute  the  update  
               Try  
                       Id  =  CType(e.Item.Cells(0).Text,  Integer)  
                       Code  =  CType(e.Item.Cells(1).Controls(0),  TextBox).Text  
                       Name  =  CType(e.Item.Cells(2).Controls(0),  TextBox).Text  
                       Type  =  CType(e.Item.Cells(3).Controls(0),  TextBox).Text  
                       Publisher  =  CType(e.Item.Cells(4).Controls(0),  TextBox).Text  
                       PurDate  =  CType(e.Item.Cells(5).Controls(0),  TextBox).Text  
                       Comment  =  CType(e.Item.Cells(6).Controls(0),  TextBox).Text  
                       updBookInfo.chgbook(Id,  Code,  Name,  Type,  Publisher,  PurDate,  Comment)  
               Catch  ex  As  SqlException  
                       lbl1.Text  =  "Sql  exception:"  &  ex.Message  
               Catch  ex  As  Exception  
                       lbl1.Text  =  "General  exception:"  &  ex.Message  
               Finally  
                       dgbook.EditItemIndex  =  -1                          
                       BindGrid(ds)  
               End  Try  
         End  Sub

解决方案 »

  1.   

    根踪一下Id,  Code,  Name,  Type,  Publisher,  PurDate,  Comment是否取到值了
    如果没有值,说明上面的赋值语句有问题
    如果取到值了,说明你的updBookInfo.chgbook有问题,可以把updBookInfo.chgbook的代码贴出来看看。
      

  2.   

    因为你刚才的贴子删除了。我怀疑是 显示数据的代码 没有放在  !IsPostBack里
      

  3.   

    在 catch{} 里把出错信息打印出来或者把 try{}catch{} 去掉,看看页面报什么错
      

  4.   

    Id  =  CType(e.Item.Cells(0).Text,  Integer)  
    Code  =  CType(e.Item.Cells(1).Controls(0),  TextBox).Text  
    Name  =  CType(e.Item.Cells(2).Controls(0),  TextBox).Text  
    Type  =  CType(e.Item.Cells(3).Controls(0),  TextBox).Text  
    Publisher  =  CType(e.Item.Cells(4).Controls(0),  TextBox).Text  
    PurDate  =  CType(e.Item.Cells(5).Controls(0),  TextBox).Text  
    Comment  =  CType(e.Item.Cells(6).Controls(0),  TextBox).Text  能取到值吗
      

  5.   

    把updBookInfo.chgbook的代码贴出来看看。
      

  6.   

    我只有这一个函数,,我的原理是先取值,再修改,,没有单独的修改函数,,我就用下面的程序修改:Id  =  CType(e.Item.Cells(0).Text,  Integer)  
    Code  =  CType(e.Item.Cells(1).Controls(0),  TextBox).Text  
    Name  =  CType(e.Item.Cells(2).Controls(0),  TextBox).Text  
    Type  =  CType(e.Item.Cells(3).Controls(0),  TextBox).Text  
    Publisher  =  CType(e.Item.Cells(4).Controls(0),  TextBox).Text  
    PurDate  =  CType(e.Item.Cells(5).Controls(0),  TextBox).Text  
    Comment  =  CType(e.Item.Cells(6).Controls(0),  TextBox).Text这样不可以么?  如果加一个修改函数该怎么写啊/?小弟我不会啊!
      

  7.   

    哦。。对比起,,我理解错了。我有那个函数的,,请看看:
    Public Function chgbook(ByVal id As Integer, _
                     ByVal code As String, _
                     ByVal name As String, _
                     ByVal type As String, _
                     ByVal publisher As String, _
                     ByVal Purchase As String, _
                     ByVal Comment As String)        Dim myCommand As SqlCommand
            Dim paraid As SqlParameter
            Dim paraName As SqlParameter
            Dim paraCode As SqlParameter
            Dim paraType As SqlParameter
            Dim paraPublisher As SqlParameter
            Dim paraPurchase As SqlParameter
            Dim paraComment As SqlParameter        myCommand = New SqlCommand("ChangeBookInfo", conn)
            myCommand.CommandType = CommandType.StoredProcedure        paraid = New SqlParameter("@BookId", SqlDbType.Int, 9)
            paraCode = New SqlParameter("@BookCode", SqlDbType.Char, 10)
            paraName = New SqlParameter("@BookName", SqlDbType.VarChar, 500)
            paraType = New SqlParameter("@BookType", SqlDbType.Char, 10)
            paraPublisher = New SqlParameter("@BookPublisher", SqlDbType.VarChar, 500)
            paraPurchase = New SqlParameter("@BookPurchaseTime", SqlDbType.Char, 10)
            paraComment = New SqlParameter("@BookComment", SqlDbType.VarChar, 500)        paraid.Value = id
            paraCode.Value = code
            paraName.Value = name
            paraType.Value = type
            paraPublisher.Value = publisher
            paraPurchase.Value = Purchase
            paraComment.Value = Comment        myCommand.Parameters.Add(id)
            myCommand.Parameters.Add(paraCode)
            myCommand.Parameters.Add(paraName)
            myCommand.Parameters.Add(paraType)
            myCommand.Parameters.Add(paraPublisher)
            myCommand.Parameters.Add(paraPurchase)
            myCommand.Parameters.Add(paraComment)        If conn.ConnectionString = "" Or conn Is Nothing Then
                getConnection()
            End If
            myCommand.ExecuteNonQuery()
            myCommand.Connection.Close()
        End Function
      

  8.   

    现在还是无法确定程序出现问题的位置
    在代码窗口中,找到
    updBookInfo.chgbook(Id,  Code,  Name,  Type,  Publisher,  PurDate,  Comment)  
    按F9,添加一个断点,执行WEB程序,看一下Id,Code等变量是否有值。
    按同样的办法看一下程序是否执行到myCommand.ExecuteNonQuery()
      

  9.   

    myCommand.Parameters.Add(id)
    改为
    myCommand.Parameters.Add(paraid)
      

  10.   

    系统这么报错怎么解决啊???谢谢,,拜托!!如下:General exception:SqlParameterCollection 仅接受非空的 SqlParameter 类型对象,不接受 Int32 对象
      

  11.   

    我在WEB上点击编辑,然后可以在各个属性框中,修改内容(被选中编辑的一项),之后我就点击更新按钮,可是:
    Id  =  CType(e.Item.Cells(0).Text,  Integer)  
    Code  =  CType(e.Item.Cells(1).Controls(0),  TextBox).Text  
    Name  =  CType(e.Item.Cells(2).Controls(0),  TextBox).Text  
    Type  =  CType(e.Item.Cells(3).Controls(0),  TextBox).Text  
    Publisher  =  CType(e.Item.Cells(4).Controls(0),  TextBox).Text  
    PurDate  =  CType(e.Item.Cells(5).Controls(0),  TextBox).Text  
    Comment  =  CType(e.Item.Cells(6).Controls(0),  TextBox).Text 
    并不能取到我修改的值,,,这个是为什么呢?
      

  12.   

    换一种方式
    在DataGrid中把你的EditTemplate中的TextBox,Label都标上Id,然后在UPdate_command中
    使用Id  = Ctype(CType(e.Item.findcontrol("lblxxx"),  Label).Text)
    的方法
      

  13.   

    http://www.heimofang.com/bbsxp/ShowPost.asp?id=7267No3有下载
    第8章第8个例子看一下