'用来更新数据
  Sub DataGrid_UpdateCommand(sender As Object, e As DataGridCommandEventArgs)
    Dim newReceivt As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
    Dim newSendtarget As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim newSenddate As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
    Dim newValiditydate As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
    Dim newClassificationt As String = CType(e.Item.Cells(5).Controls(0), TextBox).Text
 Dim newyesno As String = CType(e.Item.Cells(6).Controls(0), TextBox).Text

    Dim strSQL As String
    strSQL = "Update data Set yesno='" & newyesno & "' Where " & myDataGrid.DataKeyField & "='" & _
             myDataGrid.DataKeys(e.Item.ItemIndex) & "'"    Dim objConn As New OleDbConnection()
    objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                               "Data Source=" & Server.MapPath("data.mdb")
    objConn.Open()
    Dim objCmd As New OleDbCommand(strSQL, objConn)
    objCmd.ExecuteNonQuery
    myDataGrid.EditItemIndex = -1
    BindList()  End Sub

解决方案 »

  1.   

    “/”应用程序中的服务器错误。
    --------------------------------------------------------------------------------UPDATE 语句的语法错误。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.OleDb.OleDbException: UPDATE 语句的语法错误。源错误: 
    行 44:     objConn.Open()
    行 45:     Dim objCmd As New OleDbCommand(strSQL, objConn)
    行 46:     objCmd.ExecuteNonQuery
    行 47:     myDataGrid.EditItemIndex = -1
    行 48:     BindList()
     
      

  2.   

    你的SQL语句在Access里能执行吗?
      

  3.   

    Public Sub DataGrid1_UpDate(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
            Dim updatecomm As New SqlCommand("update lanmus Set Lanmu=@lanmu where ID=" + e.Item.Cells(0).Text, conn)
            updatecomm.Parameters.Add("@lanmu", CType(e.Item.FindControl("LanmuTitle"), TextBox).Text.Trim.ToString())
            Try
                conn.Open()
                updatecomm.ExecuteNonQuery()
            Catch ex As Exception
                Throw ex
            Finally
                conn.Close()
            End Try
            DataGrid1.EditItemIndex = -1
            ShowLanmu()
        End Sub我写的,不知对你有没有帮助.
      

  4.   

    strSQL = "Update data Set yesno='" & newyesno & "' Where " & myDataGrid.DataKeyField & "='" & myDataGrid.DataKeys(e.Item.ItemIndex) & "'"你这个是错误啊.应该是:"update Data Set yesno='"& newyesno &"' where 数据库表字段="& MyDataGrid.DataKeys(e.Item.ItemIndex)
      

  5.   

    access 肯定不能执行三access 里面哪儿来的确myDataGrid.DataKeys(e.Item.ItemIndex) & "'"这些东西嘛
      

  6.   

    objCmd.ExecuteNonQuery
     這個方法裏面怎麽沒傳參數進去啊
      

  7.   

    那你那样写肯定也是错的吧.因为你的Where没有条件可以执行.
      

  8.   

    单步执行,跟踪strSQL的最终是怎么样的字符串.
      

  9.   

    strSQL = "Update data Set yesno='" & newyesno & "' Where " & myDataGrid.DataKeyField & "='" & _
                 myDataGrid.DataKeys(e.Item.ItemIndex) & "'"---------------------------------------------------strSQL = "Update data Set yesno='" & newyesno & "' Where  xxid=" & myDataGrid.DataKeys(e.Item.ItemIndex);"
      

  10.   

    你把strSQL输出看看是什么
    有可能哪边是空值了
      

  11.   

    请问SQL的查询结果怎么输出呀?
      

  12.   

    你是说Access吧?
    对象里的"查询">>设计>>然后在菜单的"视图">>SQL视图>>>
    将你的SQL Copy到"选择查询"框,点击  运行!符号就可以运行你的SQL了
      

  13.   

    Public Sub DataGrid1_UpDate(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
    Dim newReceivt As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
        Dim newSendtarget As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
    Dim newSenddate As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
        Dim newValiditydate As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
        Dim newClassificationt As String = CType(e.Item.Cells(5).Controls(0), TextBox).Text
     Dim newyesno As String = CType(e.Item.Cells(6).Controls(0), TextBox).Text'在这儿,你可以用Response.write输出newReceivt如Response.write(newreceivt)看有没有得到值..其它几个string也是一样...
    '或者你可以用FindControl来得到TextBox的值.
            Dim updatecomm As New SqlCommand("Update data Set yesno=@yesno where ID=" + e.Item.Cells(0).Text, conn)
            updatecomm.Parameters.Add("@yesno", CType(e.Item.FindControl("yesno"), TextBox).Text.Trim.ToString())
    '其它类同
            Try
                conn.Open()
                updatecomm.ExecuteNonQuery()
            Catch ex As Exception
                Throw ex
            Finally
                conn.Close()
            End Try
            DataGrid1.EditItemIndex = -1
            BindList()'重新绑定你的数据
        End Sub
      

  14.   

    我这样写
     Dim newReceivt As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
        Dim newSendtarget As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
    Dim newSenddate As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
        Dim newValiditydate As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
        Dim newClassificationt As String = CType(e.Item.Cells(5).Controls(0), TextBox).Text
    Dim newyesno As String = CType(e.Item.Cells(6).Controls(0), TextBox).Text
    Response.write(newreceivt)
    Response.write(newSendtarget)
    Response.write(newSenddate)
    Response.write(newValiditydate)
    Response.write(newyesno)都能看到数据呀输出的数据都是正确的呀就是 update 语句不知道该怎么写了
      

  15.   

    你可以这样:
    Dim updatecomm As New SqlCommand("Update data Set yesno='123456' where ID='2'", conn)
    conn.Open()
    updatecomm.ExecuteNonQuery()
    写Command试一下,看能能更新(打开数据库刷新一下数据看有没有Update).
      

  16.   

    我把它改成
    Dim objConn As New OleDbConnection()
        objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                   "Data Source=" & Server.MapPath("data.mdb")
        objConn.Open()
        Dim objCmd As New OleDbCommand("Update data Set yesno='否' where number='0001474'",objConn)
        objCmd.ExecuteNonQuery
        myDataGrid.EditItemIndex = -1
        BindList() 然后还是
    “/”应用程序中的服务器错误。
    --------------------------------------------------------------------------------UPDATE 语句的语法错误。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.OleDb.OleDbException: UPDATE 语句的语法错误。源错误: 
    行 42:     objConn.Open()
    行 43:     Dim objCmd As New OleDbCommand("Update data Set yesno='否' where number='0001474'",objConn)
    行 44:     objCmd.ExecuteNonQuery
    行 45:     myDataGrid.EditItemIndex = -1
    行 46:     BindList() 
     源文件: E:\www\jiangyuan\show1.aspx    行: 44 
      

  17.   

    简直郁闷极了真是不知道一个SQL语句微软那个垃圾为什么要搞那么名双引号和单引号在里面搞什么嘛
      

  18.   

    Update data Set yesno='否' where number='0001474'
    在Access中能执行吗?
    把''去掉.
      

  19.   

    sql语句出错,可以在调试时设断点,查看sql语句
      

  20.   

    如果你不会跟踪出来strSQL的值,就把下面代码copy回去,然后运行,你就能看到strSQL的值了,然后在
    SQL查询分析器中单独运新这条语句,看问题出在什么地方.'用来更新数据
      Sub DataGrid_UpdateCommand(sender As Object, e As DataGridCommandEventArgs)
        Dim newReceivt As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
        Dim newSendtarget As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
    Dim newSenddate As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
        Dim newValiditydate As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
        Dim newClassificationt As String = CType(e.Item.Cells(5).Controls(0), TextBox).Text
     Dim newyesno As String = CType(e.Item.Cells(6).Controls(0), TextBox).Text

        Dim strSQL As String
        strSQL = "Update data Set yesno='" & newyesno & "' Where " & myDataGrid.DataKeyField & "='" & _
                 myDataGrid.DataKeys(e.Item.ItemIndex) & "'"
        Response.Write ("strSQL is:" & strSQL)
        Response.End()
        Dim objConn As New OleDbConnection()
        objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                   "Data Source=" & Server.MapPath("data.mdb")
        objConn.Open()
        Dim objCmd As New OleDbCommand(strSQL, objConn)
        objCmd.ExecuteNonQuery
        myDataGrid.EditItemIndex = -1
        BindList()  End Sub
      

  21.   

    晕了,原来是access,那就在access中运行抓出来的语句.
      

  22.   

    晕了
    根据 sykpboy(小憩(吃心绝对)) ( ) 提供的程序
    执行出来strSQL is:Update data Set Yesno='否' Where number='0001474'我认为这个 update语句是正确的呀可是怎么系统还是提示出错昵?
      

  23.   

    我数据库中 Yesno 以及 number 等都是文本类型的
      

  24.   

    不知道number是不是access的保留字 ?
      

  25.   

    大家好
    经过 renyu732(在学.net中...)  的帮助
    我终于搞定了原来 access 里把 yesno 做成保留字了