2016-02-13 31 views
0

得到錯誤未設置爲在SQL命令對象的實例,同時初始化命令文本.unable在SQL命令對象添加SQL更新查詢對象引用在asp.net

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 
+5

** [可能的SQL注入](https://msdn.microsoft.com/en-us/library/ms161953%28v=sql.105%29.aspx)** – lad2025

+2

將密碼存儲爲純文本並不好要麼。 – lad2025

+0

'id'爲空,您沒有在'id'中獲取任何文本框 – Hemal

回答

2

其中Control是你」的重新嘗試找到未找到,並且FindControl返回null,並且您正在使用該控件的Text(或Checked)屬性null控件。我不知道什麼是你的控件的名字,但我懷疑,這個問題是在該行:

CheckBox chkLeads = (CheckBox)gvUserDetails.Rows[e.RowIndex].FindControl("chkLeads"); 

因爲你的CheckBox ES其餘的你的名字有前綴「清潔香港」,而不是「CHK 「,嘗試解決它,並看看你的問題的前兩個意見。

相關問題