Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对象引用未设置为asp.net中sql命令中对象的实例_C#_Asp.net_Sql Server - Fatal编程技术网

C# 对象引用未设置为asp.net中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

初始化命令文本时出错。无法在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.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?