Dim updatesql As String = "update t_psw set name='" & namevalue & "',lastname='" & lastnamevalue & "',e_mail='" & emailvalue & "',tel='" & telvalue & "',address='" & addrvalue & "'where id= " & DataGrid1.DataKeys(CInt(e.Item.ItemIndex))
------------------------
你的每一个变量都取到了吗?
先把这个updatesql打印出来看看

解决方案 »

  1.   

    贴一下你的Page_Load和Update用的完整代码
      

  2.   

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '在此处放置初始化页的用户代码
            Dim strsql As String = "select * from t_psw "
            Dim dbcomm As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(strsql, connstr)
            Dim ds As New DataSet()
            dbcomm.Fill(ds, "t_psw")
            DataGrid1.DataSource = ds.Tables("t_psw").DefaultView
            DataGrid1.DataBind()
        End Sub Sub data_update(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
            Dim name As TextBox = e.Item.FindControl("name")
            Dim namevalue As String = name.Text        Dim lastname As TextBox = e.Item.FindControl("lastname")
            Dim lastnamevalue As String = lastname.Text        Dim tel As TextBox = e.Item.FindControl("tel")
            Dim telvalue As String = tel.Text        Dim e_mail As TextBox = e.Item.FindControl("e_mail")
            Dim emailvalue As String = e_mail.Text        Dim address As TextBox = e.Item.FindControl("address")
            Dim addrvalue As String = address.text
            'Label2.Text = addrvalue        Dim updatesql As String = "update t_psw set name='" & namevalue & "',lastname='" & lastnamevalue & "',e_mail='" & emailvalue & "',tel='" & telvalue & "',address='" & addrvalue & "'where id= " & DataGrid1.DataKeys(CInt(e.Item.ItemIndex))
            Dim upcommand As SqlClient.SqlCommand = New SqlClient.SqlCommand(updatesql, myconn)
            Try
                myconn.Open()
                upcommand.ExecuteNonQuery()
                myconn.Close()
                DataGrid1.EditItemIndex = -1
                bind_data()
            Catch        End Try    End Sub
      

  3.   

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '在此处放置初始化页的用户代码
            'Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)
            If Not IsPostBack Then
                Dim strsql As String = "select * from t_psw "
                Dim dbcomm As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(strsql, connstr)
                Dim ds As New DataSet()
                dbcomm.Fill(ds, "t_psw")
                DataGrid1.DataSource = ds.Tables("t_psw").DefaultView
                DataGrid1.DataBind()
            End If    End Sub
      

  4.   

    If Not IsPostBack Then!!!
      

  5.   

    楼上的先说了,我就解释一下算了
    Page_Load每次页面回发抖执行,然后才是执行你的事件
    所以你的绑定数据每次执行,你页面做的修改没办法保存,你取到的数据都是数据库里的原始数据,因此你需要只在页面第一加载的时候绑定数据:
    If Not IsPostBack Then
    绑定DataGrid
    End If
      

  6.   

    to:楼上的朋友
    如你说的没加IsPostBack,是一种情况.但楼主的情况是"点击更新时,都是空值赋了进去,把我以前的内容也更新为了空值".应该不单这种错误吧to:楼主
    http://www.yesky.com/SoftChannel/72342380468043776/20040108/1760352.shtml
      

  7.   

    把数据库中的字段值的类型和大小改改!
    如:text-->varchar
    ……