日期:2014-05-18  浏览次数:20392 次

在线急等,关于gridview更新表的问题.请各位快帮忙
数据库里面有登陆表然后想对表进行更新操作,这是定义查询用户表的代码
  Public   Sub   linker()
                Dim   conn   As   New   SqlConnection
                Dim   sql   As   String
                conn.ConnectionString   =   "data   source=192.168.31.199;initial   catalog=kaoqin   manager;user   id=james5;password=james5; "
                sql   =   "select   dengluNO,alias,name,department,useableness   from   denglu "
                Dim   cmd   As   New   SqlCommand(sql,   conn)
                conn.Open()
                Dim   dr   As   New   SqlDataAdapter(cmd)
                Dim   dl   As   New   DataSet
                dr.Fill(dl)
                GridView1.DataSource   =   dl.Tables(0).DefaultView
                GridView1.DataBind()
                conn.Close()
        End   Sub
想在gridview对表进行更新操作,这是更新的代码;
    Protected   Sub   GridView1_RowUpdating(ByVal   sender   As   Object,   ByVal   e   As   System.Web.UI.WebControls.GridViewUpdateEventArgs)   Handles   GridView1.RowUpdating
                Dim   txtnicheng,   txtname,   txtbumen,   txtkeyong   As   TextBox
                'txtbianhao   =   Me.GridView1.Rows(e.RowIndex).Cells(0).Controls(0)
                txtnicheng   =   Me.GridView1.Rows(e.RowIndex).Cells(1).Controls(0)
                txtname   =   Me.GridView1.Rows(e.RowIndex).Cells(2).Controls(0)
                txtbumen   =   Me.GridView1.Rows(e.RowIndex).Cells(3).Controls(0)
                txtkeyong   =   Me.GridView1.Rows(e.RowIndex).Cells(4).Controls(0)
                Dim   conn   As   New   SqlConnection
                conn.ConnectionString   =   "data   source=192.168.31.199;initial   catalog=kaoqin   manager;user   id=james5;password=james5; "
                Dim   sql   As   String
                sql   =   "update   denglu   set   alias= ' "   &   txtnicheng.Text   &   " ',department= ' "   &   txtbumen.Text   &   " ',name= ' "   &   txtname.Text   &   " ',useableness= "   &   txtkeyong.Text   &   "   where   dengluNO= "   &   Me.GridView1.DataKeys(e.RowIndex).Value.ToString