如何解决“ null引用异常未处理“删除gridview行.. [英] How to solve " null reference exception was unhandled " while deleting gridview row..

查看:77
本文介绍了如何解决“ null引用异常未处理“删除gridview行..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码....



受保护的子GridView1_RowDeleting(ByVal sender As Object,ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs)Handles GridView1.RowDeleting



Here is my code....

Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting

Dim vacid As Integer = Convert.ToInt32(DirectCast(GridView1.Rows(e.RowIndex).FindControl("txtVacid"), TextBox).Text)
      Dim myCommand As New SqlCommand
      Dim myConnection = New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
      Dim update As String
      Dim strsql As String
      myCommand.Connection = myConnection
      'vacid = CInt(GridView1.Rows(GridView1.SelectedRow.RowIndex).Cells(0).Text)
      update = "Delete  from  Pat_Vaccine_Details   where vaccine_id='" & vacid & "'"
      myCommand = New SqlCommand(update, myConnection)
      myConnection.Open()
      myCommand.ExecuteNonQuery()
      myCommand.Connection.Close()
      BindGrid()
  End Sub





在删除时,我收到此错误



空引用异常未处理



请帮助



while deleting , i got this error

"null reference exception was unhandled "

please help

推荐答案

嗯......也许如果你没有注释掉设置 vacid 值的那一行帮助?



如果不是,那么你需要使用调试器来查看引发异常的行(你还没有告诉我们那个)并找到哪个值 null / Nothing 然后回顾你的代码以找出原因。



我们不能为你做到这一点:我们无法运行您的代码,查看您的屏幕,访问您的硬盘或阅读您的想法......
Um...perhaps if you hadn't commented out the line which sets the vacid value it would help?

If it isn;t that, then you need to use the debugger to look at the line that is throwing the exception (and you haven't told us that) and find which value is null / Nothing and then look back in your code to find out why.

We can't do that for you: we can't run your code, see your screen, access your HDD, or read your mind...


这篇关于如何解决“ null引用异常未处理“删除gridview行..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆