C# 对象引用未设置为asp.net中sql命令中对象的实例
初始化命令文本时出错。无法在sql命令对象中添加sql更新查询C# 对象引用未设置为asp.net中sql命令中对象的实例,c#,asp.net,sql-server,C#,Asp.net,Sql Server,初始化命令文本时出错。无法在sql命令对象中添加sql更新查询 TextBox id = (TextBox)gvUserDetails.Rows[e.RowIndex].FindControl("txtid"); TextBox Loginid = (TextBox)gvUserDetails.Rows[e.RowIndex].FindControl("txtgvusername"); TextBox EmployeeId = (TextBox)gvUserDetails.Rows[e.RowI
TextBox id = (TextBox)gvUserDetails.Rows[e.RowIndex].FindControl("txtid");
TextBox Loginid = (TextBox)gvUserDetails.Rows[e.RowIndex].FindControl("txtgvusername");
TextBox EmployeeId = (TextBox)gvUserDetails.Rows[e.RowIndex].FindControl("txtEmployeeId");
TextBox Fullname = (TextBox)gvUserDetails.Rows[e.RowIndex].FindControl("txtFullname");
TextBox Password = (TextBox)gvUserDetails.Rows[e.RowIndex].FindControl("txtPassword");
TextBox ContactNo = (TextBox)gvUserDetails.Rows[e.RowIndex].FindControl("txtContactNo");
TextBox MailId = (TextBox)gvUserDetails.Rows[e.RowIndex].FindControl("txtMailid");
TextBox Location = (TextBox)gvUserDetails.Rows[e.RowIndex].FindControl("txtLocation");
TextBox Roles = (TextBox)gvUserDetails.Rows[e.RowIndex].FindControl("txtRoles");
CheckBox chkLeads = (CheckBox)gvUserDetails.Rows[e.RowIndex].FindControl("chkLeads");
CheckBox ChkSales = (CheckBox)gvUserDetails.Rows[e.RowIndex].FindControl("ChkSales");
CheckBox ChkReports = (CheckBox)gvUserDetails.Rows[e.RowIndex].FindControl("ChkReports");
CheckBox ChkPayments = (CheckBox)gvUserDetails.Rows[e.RowIndex].FindControl("ChkPayments");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Update tbl_AdminLogin set FullName='" + txtfullName.Text + "',Password='" + txtPassword.Text + "',ContactNo='" + txtContact.Text + "',Mailid='" + txtMailid.Text + "',Location='" + txtLocation.Text + "',Roles='" + Roles.Text + "',Leads='" + chkLeads.Text + "',Sales='" + ChkSales.Checked + "',Reports='" + ChkSales.Text + "',Payments='" + ChkPayments.Text + "',EmployeeId='" + id.Text + "' where id='" + id.Text + "'";//getting error here
您试图查找的
控件之一
找不到,而FindControl
返回了null
,并且您正在使用该null
控件的文本
(或选中
)属性。我不知道您的控件的名称,但我怀疑问题出在这一行:
CheckBox chkLeads = (CheckBox)gvUserDetails.Rows[e.RowIndex].FindControl("chkLeads");
因为您的
复选框的其余部分的名称得到了前缀“Chk”而不是“Chk”,所以请尝试修复它,并查看关于您的问题的前两条注释。您试图查找的控件之一找不到,而FindControl
返回了null
,您使用的是null
控件的Text
(或Checked
)属性。我不知道您的控件的名称,但我怀疑问题出在这一行:
CheckBox chkLeads = (CheckBox)gvUserDetails.Rows[e.RowIndex].FindControl("chkLeads");
因为您将复选框的其余部分的名称改为前缀“Chk”而不是“Chk”,请尝试修复它,并查看关于您的问题的前两条注释。将密码存储为纯文本也不是好主意。id
为空,您在id
no..id中没有任何文本框。im获取id值是“18”由于缺少更多信息,这是一个猜测:NullReferenceException作为一个文本框为空?将密码存储为纯文本也不是一个好主意。id
为空,您在id
no..id中没有获取任何文本框。由于缺少更多信息,im getting id值为“18”是一个猜测:NullReferenceException作为一个文本框为null?