![VB.NET源码-156个实用实例哦……](http://www.zhzx123.com/VB.NET_03.gif)
detailsview 的更新、插入、删除操作遇到的问题
Protected Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles DetailsView1.ItemUpdating
Dim con As New SqlConnection()
con.ConnectionString = "Data Source=UPC-DING;Initial Catalog=bysj;User ID=sa ; "
con.Open()
Dim sql As String
sql = "update [保养标准项目] set 序号= '' " & DetailsView1.Rows(2).Cells(0).Text().ToString().Trim() & " '' 分类编号= '' " & DetailsView1.Rows(2).Cells(1).Text().ToString().Trim() & " ''分类名称= '' " & DetailsView1.Rows(2).Cells(2).Text().ToString().Trim() & " '' 项目编号= '' " & DetailsView1.Rows(2).Cells(3).Text().ToString().Trim() & " '' 项目名称= '' " & DetailsView1.Rows(2).Cells(4).Text().ToString().Trim() & " '' 项目描述= '' " & DetailsView1.Rows(2).Cells(5).Text().ToString().Trim() & " '' "
Dim ds As New DataSet()
Dim adp As New SqlDataAdapter()
Dim cmd As New SqlCommand()
cmd.Parameters.Clear()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = sql
adp.SelectCommand = cmd
'' adp.UpdateCommand = cmd
adp.Fill(ds, "by ")
DetailsView1.DataSource = ds.Tables( "by ").DefaultView
DetailsView1.DataBind()
con.Close()
End Sub
可是总是提示出现以下错误:
指定的参数已超出有效值的范围。
参数名: index
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。
参数名: index
''update 表 set 字段1= ''
'' + (GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim() + " ''
在detailsview中参数‘RowIndex’不存在阿?这个怎么解释,我刚接触这个,还是菜鸟,还请高手指教。
detailsview 的更新、插入、删除操作该如何写??求源码?
__________________________________________________________________________
我是用gridview显示数据库的内容,用detailsview更新数据库里的内容,该怎么办?
__________________________________________________________________________
怎么没人支持??
__________________________________________________________________________
adp.SelectCommand = cmd加上这一句试试cmd。ExecuteNonQuery
__________________________________________________________________________
Cells(2),里面的数字全写改成1就OK了。
__________________________________________________________________________