(当我点击删除按钮时向我显示)从gridview中删除一行?请回答 [英] (Display to me when I click delete button ) to delete a row from a gridview ? plz answer
问题描述
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
我尝试过:
受保护的Sub ButDel_Click(ByVal sender As Object,ByVal e As System.EventArgs)处理ButDel.Click
For i = 0 To GridView1.Rows.Count - 1
如果CType(GridView1.Rows(i).FindControl(CheckBox1),CheckBox).Checked = True则
如果Session(y)= 1则
否则
会话(y)= 2
Dim conn As New SqlConnection
Dim cmmd As New SqlCommand(setupPro2)
Dim Adapter As New SqlDataAdapter
cmmd.CommandType = CommandType.StoredProcedure
Dim dss As New DataSet
Dim dtt As New DataTable
conn.ConnectionString =Server = .; Database = setup_set; User Id = sa; Pass word = 123;
cmmd.Connection = conn
Adapter.SelectCommand = cmmd
cmmd.Parameters.Add(@ Id, SqlDbType.Int)
cmmd.Parameters(@ Id)。Value = CType(GridView1.Rows(i).FindControl(TxtId),TextBox).Text
cmmd.Parameters.Add(@ Setup_Type,SqlDbType.Int)
cmmd.Parameters(@ Setup_Type)。Value = Session(y)
cmmd.Parameters.Add(@ Setup_name,SqlDbType.VarChar)
cmmd.Parameters(@ Setup_name)。Value = CType(GridView1.Rows(i).FindControl(TxtName) ),TextBox).Text
cmmd.Parameters.Add(@ x,SqlDbType.VarChar)
cmmd.Parameters(@ x)。Value = 3
conn.Open()
Adapter.Fill(dss,tabel1)
conn.Close()
Session(LoadData)= dss.Tables(tabel1)
GridView1.DataSource = dss.Tables(tabel1)
GridView1.DataBind()
'会话(LoadData)= dss.Tables(tabel1)
结束如果
结束如果
下一页
结束Sub
What I have tried:
Protected Sub ButDel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButDel.Click
For i = 0 To GridView1.Rows.Count - 1
If CType(GridView1.Rows(i).FindControl("CheckBox1"), CheckBox).Checked = True Then
If Session("y") = 1 Then
Else
Session("y") = 2
Dim conn As New SqlConnection
Dim cmmd As New SqlCommand("setupPro2")
Dim Adapter As New SqlDataAdapter
cmmd.CommandType = CommandType.StoredProcedure
Dim dss As New DataSet
Dim dtt As New DataTable
conn.ConnectionString = "Server=.;Database=setup_set;User Id=sa; Password=123;"
cmmd.Connection = conn
Adapter.SelectCommand = cmmd
cmmd.Parameters.Add("@Id", SqlDbType.Int)
cmmd.Parameters("@Id").Value = CType(GridView1.Rows(i).FindControl("TxtId"), TextBox).Text
cmmd.Parameters.Add("@Setup_Type", SqlDbType.Int)
cmmd.Parameters("@Setup_Type").Value = Session("y")
cmmd.Parameters.Add("@Setup_name", SqlDbType.VarChar)
cmmd.Parameters("@Setup_name").Value = CType(GridView1.Rows(i).FindControl("TxtName"), TextBox).Text
cmmd.Parameters.Add("@x", SqlDbType.VarChar)
cmmd.Parameters("@x").Value = 3
conn.Open()
Adapter.Fill(dss, "tabel1")
conn.Close()
Session("LoadData") = dss.Tables("tabel1")
GridView1.DataSource = dss.Tables("tabel1")
GridView1.DataBind()
'Session("LoadData") = dss.Tables("tabel1")
End If
End If
Next
End Sub
推荐答案
在不知道哪一行的情况下,我建议你从检查拼写开始。
如果您的数据库表名为tabel1,那么它应该可以工作 - 但如果它在您的数据库中拼写为table1,那么您将收到此错误,因为Fill方法不会返回任何DataTables。
检查返回以确保至少有一个表,并且该表至少包含一行,这也是一个好主意。如果没有,则记录问题和/或通知用户。
Without knowing which line, I'd suggest that you start by checking your spelling.
If your database table is called "tabel1" then it should work - but if it's spelled correctly in your database as "table1" then you will get this error as the Fill method will not return any DataTables.
It's also a good idea to check returns to makes sure that you got at least one table, and that the table contains at least one row. If it doesn't, then log the problem and / or inform the user.
这篇关于(当我点击删除按钮时向我显示)从gridview中删除一行?请回答的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!