asp.net中的Gridview错误 [英] Gridview in asp.net Error
本文介绍了asp.net中的Gridview错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨..
尝试执行gridview_rowupdatin()event
时,GridView中出现错误
错误:用户代码未处理NullReferenceException
对象引用未设置为对象的实例
我在这里干什么...?
受保护的 子 GrdHRProcess_RowCommand( ByVal 发件人 As 对象, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)句柄 GrdHRProcess.RowCommand
Dim MyConnection1 As SqlConnection
Dim uid As 字符串
MyConnection1 = 新建 SqlConnection(ConfigurationManager.ConnectionStrings(" ).ConnectionString)
Dim sql1 As String
sql1 = "
Dim com As SqlCommand = 新建 SqlCommand( sql1,MyConnection1)
com.Connection.Open()
uid = Convert.ToString(com.ExecuteScalar)
com.Connection.Close()
uid = uid + 1
Dim conn As 新建 SqlConnection
conn = 新建 SqlConnection(ConfigurationManager.ConnectionStrings(" ).ConnectionString)
如果(e.CommandName.Equals(" ))然后
Dim txtNewName1 As TextBox = GrdHRProcess.FooterRow.FindControl(" txtNewName")
Dim txtNewContact1 As TextBox = GrdHRProcess.FooterRow.FindControl(" txtNewContact")
Dim txtNewCallDate1 As TextBox = GrdHRProcess.FooterRow.FindControl(" txtNewCallDate")
Dim txtNewCallTime1 As TextBox = GrdHRProcess.FooterRow.FindControl(" txtNewCallTime")
Dim txtNewStartDate1 As TextBox = GrdHRProcess.FooterRow.FindControl(" txtNewSD")
Dim txtNewClass1 As TextBox = GrdHRProcess.FooterRow.FindControl(" txtNewClass")
Dim ddlNewStatus1 As DropDownList = GrdHRProcess.FooterRow.FindControl(" ddlNewStatus")
conn.Open()
Dim cmd As 新建 SqlCommand(" & uid& " & txtNewName1.Text& " & txtNewContact1.Text& " ','"& txtNewCallDate1.Text& ','"& txtNewCallTime1.Text& ','"& ; txtNewStartDate1.Text& " & txtNewClass1.Text& " & ddlNewStatus1.Text& " ,conn)
cmd.ExecuteNonQuery()
conn.Close()
结束 如果
结束 子
解决方案
该异常是不言自明的,NullReferenceException表示您正在尝试访问指向null的对象引用上的成员字段或函数类型.
希望对您有所帮助:)
有关更多查询,请在此处评论!!Hi ..
i m getting Error in Gridview when i m trying to gridview_rowupdatin()event
error : NullReferenceException was Unhandled by user code
object reference not set to an instance of an object
What i m doing wreong here..?
Protected Sub GrdHRProcess_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GrdHRProcess.RowCommand Dim MyConnection1 As SqlConnection Dim uid As String MyConnection1 = New SqlConnection(ConfigurationManager.ConnectionStrings("HRProcessConnectionString").ConnectionString) Dim sql1 As String sql1 = "select max(UDetailId) from HRProcess_Detail" Dim com As SqlCommand = New SqlCommand(sql1, MyConnection1) com.Connection.Open() uid = Convert.ToString(com.ExecuteScalar) com.Connection.Close() uid = uid + 1 Dim conn As New SqlConnection conn = New SqlConnection(ConfigurationManager.ConnectionStrings("HRProcessConnectionString").ConnectionString) If (e.CommandName.Equals("AddNew")) Then Dim txtNewName1 As TextBox = GrdHRProcess.FooterRow.FindControl("txtNewName") Dim txtNewContact1 As TextBox = GrdHRProcess.FooterRow.FindControl("txtNewContact") Dim txtNewCallDate1 As TextBox = GrdHRProcess.FooterRow.FindControl("txtNewCallDate") Dim txtNewCallTime1 As TextBox = GrdHRProcess.FooterRow.FindControl("txtNewCallTime") Dim txtNewStartDate1 As TextBox = GrdHRProcess.FooterRow.FindControl("txtNewSD") Dim txtNewClass1 As TextBox = GrdHRProcess.FooterRow.FindControl("txtNewClass") Dim ddlNewStatus1 As DropDownList = GrdHRProcess.FooterRow.FindControl("ddlNewStatus") conn.Open() Dim cmd As New SqlCommand("Insert into HRProcess_Detail(UDetailId,CandidateName,ContactNo,CallDate,CallTime,StartDate,Class,Status) values('" & uid & "','" & txtNewName1.Text & "','" & txtNewContact1.Text & "','" & txtNewCallDate1.Text & "', '" & txtNewCallTime1.Text & "','" & txtNewStartDate1.Text & "', '" & txtNewClass1.Text & "','" & ddlNewStatus1.Text & "')", conn) cmd.ExecuteNonQuery() conn.Close() End If End Sub解决方案the exception is self explanatory, NullReferenceException refers that you are trying to access member fields or function types on an object reference that points to null.
hope it helps :)
for further queries comment here!!
这篇关于asp.net中的Gridview错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文