数据库里面有登陆表然后想对表进行更新操作,这是定义查询用户表的代码
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
Dim cmd As New SqlCommand(sql, conn)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Me.GridView1.EditIndex = -1
Call linker()
End Sub
一点更新就会出错,并且提示索引不能超出范围.请问这些代码哪儿有问题,为什么索引会超出范围,gridview第一列是编号(dengluNO)第二例是呢称(alias),第三列是姓名(name),第四列是所属部门(department),第五列是是否可用(useableness)接下来两列是编辑和删除,肯定大家帮忙
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
Dim cmd As New SqlCommand(sql, conn)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Me.GridView1.EditIndex = -1
Call linker()
End Sub
一点更新就会出错,并且提示索引不能超出范围.请问这些代码哪儿有问题,为什么索引会超出范围,gridview第一列是编号(dengluNO)第二例是呢称(alias),第三列是姓名(name),第四列是所属部门(department),第五列是是否可用(useableness)接下来两列是编辑和删除,肯定大家帮忙
解决方案 »
- webBrowser为什么获得不到JS中的值
- 书籍比较
- 基于web的视频在线聊天怎么做,高手请进
- (急)将带有图片和文字(新闻内容)的数据存入到Informix,程序中和Informix中应用何数据类型?
- 求救高手(关于.net问题) 急呀!!!
- TextBox1的TextMode是多行的,如何在TextBox1的后面加多一行字符"aaaaaa",,,,,
- 移植项目,Session丢失的问题
- 大虾们,帮帮忙,看一下我的这段控件为什么什么也显示不了!!!救救!!在线等
- 不知道大家遇到过这样的问题没有!
- 求象TREEVIEW功能的JS,具体要求见内(分数无限):
- 做用户登录系统时出错
- data grid控件添加数据出现错误
怎么没星星划过呢```顶顶