救命啊,DATAGRID中更新数据出现“指定控件转换无效”
哪位大侠给指导一下,谢谢了!
代码:
Private Sub ResourceInList_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles ResourceInList.UpdateCommand
Dim shebeibianhao, shebeimingcheng, shebeiguige, lingyongbumen, lingyongren, lingyongriqi, bdbh As TextBox
bdbh = e.Item.Cells(0).Controls(0)
shebeibianhao = e.Item.Cells(1).Controls(0)
shebeimingcheng = e.Item.Cells(2).Controls(0)
shebeiguige = e.Item.Cells(3).Controls(0)
lingyongbumen = e.Item.Cells(4).Controls(0)
lingyongren = e.Item.Cells(5).Controls(0)
lingyongriqi = e.Item.Cells(6).Controls(0)
Dim myConn As New SqlClient.SqlConnection
Dim myCmd As New SqlClient.SqlCommand
Dim myDataAdapter As New SqlClient.SqlDataAdapter
Dim connstr As String
connstr = ConfigurationSettings.AppSettings("dsn")
myConn.ConnectionString = connstr
myConn.Open()
myCmd.CommandText = "update tblshebeilingyong set shebeibianhao=@shebeibianhao,shebeimingcheng=@shebeimingcheng,shebeiguige=@shebeiguige,lingyongbumen=@lingyongbumen,lingyongyuangong=@lingyongren,lingyongriqi=@lingyongriq where bdbh=@bdbh"
myCmd.Parameters.Clear()
myCmd.Parameters.Add(New SqlClient.SqlParameter("@shebeibianhao", SqlDbType.VarChar, 50))
myCmd.Parameters.Add(New SqlClient.SqlParameter("@shebeimingcheng", SqlDbType.VarChar, 50))
myCmd.Parameters.Add(New SqlClient.SqlParameter("@shebeiguige", SqlDbType.VarChar, 200))
myCmd.Parameters.Add(New SqlClient.SqlParameter("@shebeizhuangtai", SqlDbType.VarChar, 50))
myCmd.Parameters.Add(New SqlClient.SqlParameter("@lingyongriqi", SqlDbType.SmallDateTime, 4))
myCmd.Parameters.Add(New SqlClient.SqlParameter("@lingyongbumen", SqlDbType.VarChar, 50))
myCmd.Parameters.Add(New SqlClient.SqlParameter("@lingyongren", SqlDbType.VarChar, 50))
myCmd.Parameters.Add(New SqlClient.SqlParameter("@bdbh", SqlDbType.VarChar, 50))
myDataAdapter.SelectCommand.Parameters("@shebeibianhao").Value = Trim(shebeibianhao.Text)
myDataAdapter.SelectCommand.Parameters("@shebeimingcheng").Value = Trim(shebeimingcheng.Text)
myDataAdapter.SelectCommand.Parameters("@shebeiguige").Value = Trim(shebeiguige.Text)
myDataAdapter.SelectCommand.Parameters("@lingyongriqi").Value = Trim(lingyongriqi.Text)
myDataAdapter.SelectCommand.Parameters("@lingyongbumen").Value = Trim(lingyongbumen.Text)
myDataAdapter.SelectCommand.Parameters("@lingyongren").Value = Trim(lingyongyuangong.Text)
myDataAdapter.SelectCommand.Parameters("@bdbh").Value = ResourceInList.DataKeys.Item(e.Item.ItemIndex)
myConn.Open()
myCmd.ExecuteNonQuery()
myConn.Close()
ResourceInList.EditItemIndex = -1
BindResourceInData()
End Sub
--------------------------------------------------------------------------------
指定的转换无效。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidCastException: 指定的转换无效。
源错误:
行 192: Private Sub ResourceInList_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles ResourceInList.UpdateCommand
行 193: Dim shebeibianhao, shebeimingcheng, shebeiguige, lingyongbumen, lingyongren, lingyongriqi, bdbh As TextBox
行 194: bdbh = e.Item.Cells(0).Controls(0)
行 195: shebeibianhao = e.Item.Cells(1).Controls(0)
行 196: shebeimingcheng = e.Item.Cells(2).Controls(0)
代码:
Private Sub ResourceInList_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles ResourceInList.UpdateCommand
Dim shebeibianhao, shebeimingcheng, shebeiguige, lingyongbumen, lingyongren, lingyongriqi, bdbh As TextBox
bdbh = e.Item.Cells(0).Controls(0)
shebeibianhao = e.Item.Cells(1).Controls(0)
shebeimingcheng = e.Item.Cells(2).Controls(0)
shebeiguige = e.Item.Cells(3).Controls(0)
lingyongbumen = e.Item.Cells(4).Controls(0)
lingyongren = e.Item.Cells(5).Controls(0)
lingyongriqi = e.Item.Cells(6).Controls(0)
Dim myConn As New SqlClient.SqlConnection
Dim myCmd As New SqlClient.SqlCommand
Dim myDataAdapter As New SqlClient.SqlDataAdapter
Dim connstr As String
connstr = ConfigurationSettings.AppSettings("dsn")
myConn.ConnectionString = connstr
myConn.Open()
myCmd.CommandText = "update tblshebeilingyong set shebeibianhao=@shebeibianhao,shebeimingcheng=@shebeimingcheng,shebeiguige=@shebeiguige,lingyongbumen=@lingyongbumen,lingyongyuangong=@lingyongren,lingyongriqi=@lingyongriq where bdbh=@bdbh"
myCmd.Parameters.Clear()
myCmd.Parameters.Add(New SqlClient.SqlParameter("@shebeibianhao", SqlDbType.VarChar, 50))
myCmd.Parameters.Add(New SqlClient.SqlParameter("@shebeimingcheng", SqlDbType.VarChar, 50))
myCmd.Parameters.Add(New SqlClient.SqlParameter("@shebeiguige", SqlDbType.VarChar, 200))
myCmd.Parameters.Add(New SqlClient.SqlParameter("@shebeizhuangtai", SqlDbType.VarChar, 50))
myCmd.Parameters.Add(New SqlClient.SqlParameter("@lingyongriqi", SqlDbType.SmallDateTime, 4))
myCmd.Parameters.Add(New SqlClient.SqlParameter("@lingyongbumen", SqlDbType.VarChar, 50))
myCmd.Parameters.Add(New SqlClient.SqlParameter("@lingyongren", SqlDbType.VarChar, 50))
myCmd.Parameters.Add(New SqlClient.SqlParameter("@bdbh", SqlDbType.VarChar, 50))
myDataAdapter.SelectCommand.Parameters("@shebeibianhao").Value = Trim(shebeibianhao.Text)
myDataAdapter.SelectCommand.Parameters("@shebeimingcheng").Value = Trim(shebeimingcheng.Text)
myDataAdapter.SelectCommand.Parameters("@shebeiguige").Value = Trim(shebeiguige.Text)
myDataAdapter.SelectCommand.Parameters("@lingyongriqi").Value = Trim(lingyongriqi.Text)
myDataAdapter.SelectCommand.Parameters("@lingyongbumen").Value = Trim(lingyongbumen.Text)
myDataAdapter.SelectCommand.Parameters("@lingyongren").Value = Trim(lingyongyuangong.Text)
myDataAdapter.SelectCommand.Parameters("@bdbh").Value = ResourceInList.DataKeys.Item(e.Item.ItemIndex)
myConn.Open()
myCmd.ExecuteNonQuery()
myConn.Close()
ResourceInList.EditItemIndex = -1
BindResourceInData()
End Sub
--------------------------------------------------------------------------------
指定的转换无效。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidCastException: 指定的转换无效。
源错误:
行 192: Private Sub ResourceInList_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles ResourceInList.UpdateCommand
行 193: Dim shebeibianhao, shebeimingcheng, shebeiguige, lingyongbumen, lingyongren, lingyongriqi, bdbh As TextBox
行 194: bdbh = e.Item.Cells(0).Controls(0)
行 195: shebeibianhao = e.Item.Cells(1).Controls(0)
行 196: shebeimingcheng = e.Item.Cells(2).Controls(0)
...全文
相关推荐
vb中datagrid控件的详细使用方法
确保选择的是“Microsoft DataGrid Control”而不是其他版本或类似的控件。2.
WPF Datagrid 分页控件实现教程
分页是将信息量庞大的数据集分成较小、易于管理的块,每次仅展示其中的一部分给用户。这一概念在计算机科学和信息技术中广泛使用,特别是在用户界面设计和数据库操作中。分页机制的引入极大地提高了用户体验,因为它可以减少单次加载的数据量,加速内容的展示速度,降低内存使用,从而提升应用程序的响应性和性能。ICollection是一个定义在.NET Framework中的接口,它提供了用于访问集合的基本方法和属性。当与CollectionView一起使用时,此接口的以下方法特别重要:Count。
Microsoft DataGrid控件
msstdfmt.dll是标准格式化库,它提供了数据格式化和转换的功能,对于DataGrid控件的数据展示至关重要。同样,这个文件也需要注册,命令为`regsvr32 msstdfmt.dll`。
博图WinCC V16用ADODB、DataGrid控件显示SQL Server数据.docx
首先,我们需要在画面中添加一个DataGrid控件,这个控件可以用来展示来自数据库的表格数据。DataGrid控件允许用户以网格形式查看、编辑和管理数据,非常适合用于数据显示和交互。
Datagrid 控件 及注册 MSDATGRD.OCX
msstdfmt.dll"是另一个重要的文件,它是Microsoft Standard Data Formatting Library的缩写,这个库包含了处理数据格式化和转换的功能,对于像Datagrid


