数据库中的数据是否被修改了?
是否需要重新绑定DataGrid。。

解决方案 »

  1.   

    检查在Page_Load中绑定DataGrid的代码,有没有放在IsPostBack里面。
      

  2.   

    icyer是对的,我以前也遇上过,如果不是第一次加载页面时绑定,那么你的修改是没用的,
      

  3.   

    我的Page_Load是这样的,对吗?Sub Page_Load(Sender As Object, E As EventArgs)
          If Not (IsPostBack)
            BindGrid()
          End If
            panel1.visible=false
    End Sub
      

  4.   

    grid1.DataKeys
    相应的字段你有没有搞错呀.
      

  5.   

    你更新完,要重新绑定的,你的BindGrid()是怎么写的呀?
    有时BindGrid()的原因,绑定不生效的
      

  6.   

    绑定部分:Sub BindGrid()
    dim MyConnection as OleDbConnection
     MyConnection= new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("test1.mdb"))
    Dim DS As DataSet
    Dim MyCommand As OleDbDataAdapter
          
    MyCommand = new OleDbDataAdapter("select * from TEST", MyConnection)
          
    DS = new DataSet
    MyCommand.Fill(DS)
          
    grid1.DataSource=DS.Tables(0).DefaultView
    grid1.DataBind()
    End Sub我做单步调试,总是过不去:
    =================================
    ……
    Dim UpdateCmd As String = "UPDATE TEST SET name = @name,address = @address,zip = @zip  where id = @id "MyCommand = New OleDbCommand(UpdateCmd, MyConnection)
     
    Dim Cols As String() = {"@INGNO","@RUNNO","@DIAMETER"}
    Dim CurrentTextBox As TextBoxMyCommand.Parameters.Add(New OleDbParameter("@Id", OleDbType.VarChar, 40))
    MyCommand.Parameters("@Id").Value = grid1.DataKeys(CInt(E.Item.ItemIndex))
            
    MyCommand.Parameters.Add(New OleDbParameter("@name", OleDbType.VarChar, 40))
    CurrentTextBox = E.Item.Cells(2).Controls(0)
    Dim ColValue As String = CurrentTextBox.Text
    MyCommand.Parameters(Cols(1)).Value = ColValue
            
    MyCommand.Parameters.Add(New OleDbParameter("@address", OleDbType.VarChar, 40))
    CurrentTextBox = E.Item.Cells(3).Controls(0)
    ColValue = CurrentTextBox.Text
    MyCommand.Parameters(Cols(2)).Value = ColValue
            
            
    MyCommand.Parameters.Add(New OleDbParameter("@zip",OleDbType.VarChar, 40))
    CurrentTextBox = E.Item.Cells(4).Controls(0)
    ColValue = CurrentTextBox.Text
    MyCommand.Parameters(Cols(3)).Value = ColValue=============================================
    这样对不对,系统总说“System.IndexOutOfRangeException: 此 OleDbParameterCollection 中未包含带有 ParameterName“@address”的 OleDbParameter。
    ”,这又是为什么呢?
      

  7.   

    你是不是没有在DATAGRID的DATAKEYFIELD属性中选中ADDRESS?