导航
  • 主页
  • VBS
  • .NET技术
  • VBA
  • VB网络编程
  • VB多媒体
  • VB数据库
  • VB控件
  • VB COM/DCOM
  • VB基础类
  • VB API
  • 问答

新人 求看DATAGRID更新报错问题

ch00549476 2006-05-20 12:42:34
Input string was not in a correct format.
Line 78: Dim hwname As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Line 79: Dim sj As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Line 80: Dim userid As Integer = CInt(DataGrid1.DataKeys(CInt(e.Item.ItemIndex)))

程序代码
mycn As SqlConnection
Dim myda As SqlDataAdapter
Dim ds As DataSet
Dim strConn, strSQL As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
strConn = "server=127.0.0.1;uid=sa;database=xs;pwd=1234;"
If Not Page.IsPostBack Then
BindGrid()
End If
'在此处放置初始化页的用户代码
End Sub
Sub BindGrid()
mycn = New SqlConnection(strConn)
strSQL = "Select * from [dd] "
myda = New SqlDataAdapter(strSQL, mycn)
ds = New DataSet
myda.Fill(ds, "Table")
DataGrid1.DataSource = ds
DataGrid1.DataBind()
End Sub


Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
BindGrid()
End Sub

Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
DataGrid1.EditItemIndex = CInt(e.Item.ItemIndex)
BindGrid()
End Sub

Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim hwname As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Dim sj As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Dim userid As Integer = CInt(DataGrid1.DataKeys(CInt(e.Item.ItemIndex)))
Try
Dim updateCmd As String = "UPDATE [dd] SET hwname = @hwname," + "sj = @sj , userid = @userid where bh =@bh "
Dim cn As New SqlConnection(strConn)
Dim myCommand As New SqlCommand(updateCmd, cn)
myCommand.Parameters.Add(New SqlParameter("@hwname", Convert.ToDecimal(hwname)))
myCommand.Parameters.Add(New SqlParameter("@sj", Convert.ToInt16(sj)))
myCommand.Parameters.Add(New SqlParameter("@userid", userid))
cn.Open()
myCommand.ExecuteNonQuery()
DataGrid1.EditItemIndex = -1
BindGrid()
Catch ex As Exception
lblError.Visible = True
lblError.Text = ex.Message

End Try

End Sub

End Class

...全文
44 点赞 收藏 3
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ch00549476 2006-05-20
Input string was not in a correct format 这个是自己做LBL显示的信息
回复
ch00549476 2006-05-20
全部都Controls(0)改成Controls(1)吗?
回复
fallen_chen 2006-05-20
Line 78: Dim hwname As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Line 79: Dim sj As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text

Controls(0)改成Controls(1)
回复
发动态
发帖子
VB
创建于2007-09-28

1.5w+

社区成员

VB技术相关讨论,主要为经典vb,即VB6.0
申请成为版主
社区公告
暂无公告