我有一个贷方页面,在其中显示数据库中的所有贷方,因为当我单击显示此错误的按钮时,我可以选择编辑贷方。
System.NullReferenceException: 'Object reference not set to an instance of an object.'
System.Collections.Specialized.NameValueCollection.this[string].get returned null.`
代码是这个
ViewState["lender_id"] = lenderid = Convert.ToInt32(Request.QueryString["lender_id"].ToString());
这是我认为的方法
private void Get_lender_data_to_update()
{
ViewState["lender_id"] = lenderid = Convert.ToInt32(Request.QueryString["lender_id"].ToString());
using (dtst = bal.Getlenderedit(lenderid))
{
lender_name.Text = dtst.Tables[0].Rows[0]["lender_name"].ToString();
lender_code.Text = dtst.Tables[0].Rows[0]["lender_code"].ToString();
//ddlselect.SelectedValue = dtst.Tables[0].Rows[0]["Gender"].ToString();
manager_name.Text = dtst.Tables[0].Rows[0]["manager_name"].ToString();
manager_number.Text = dtst.Tables[0].Rows[0]["manager_number"].ToString();
lc_number.Text = dtst.Tables[0].Rows[0]["lc_number"].ToString();
manager_email.Text = dtst.Tables[0].Rows[0]["manager_email"].ToString();
lc_email.Text = dtst.Tables[0].Rows[0]["lc_email"].ToString();
contact_name.Text = dtst.Tables[0].Rows[0]["contact_name"].ToString();
designation.Text = dtst.Tables[0].Rows[0]["designation"].ToString();
branch_name.Text = dtst.Tables[0].Rows[0]["branch_name"].ToString();
branch_add.Text = dtst.Tables[0].Rows[0]["branch_add"].ToString();
branch_add2.Text = dtst.Tables[0].Rows[0]["branch_add2"].ToString();
branch_city.Text = dtst.Tables[0].Rows[0]["branch_city"].ToString();
branch_state.Text = dtst.Tables[0].Rows[0]["branch_state"].ToString();
branch_zip.Text = dtst.Tables[0].Rows[0]["branch_zip"].ToString();
branch_country.Text = dtst.Tables[0].Rows[0]["branch_country"].ToString();
}
}
这是我的bal.Getlenderedit
public DataSet Getlenderedit(int lenderid)
{
return dal.Getlenderedit(lenderid);
}
这是我的儿子。Getlenderedit
public DataSet Getlenderedit(int lenderid)
{
try
{
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@lenderid", lenderid);
DataSet lenderedit = dbmngr.ExecuteAdapter(cmd, CommandType.StoredProcedure, "editlender");
return lenderedit;
}
catch (Exception ex)
{
throw ex;
}
}
答案 0 :(得分:0)
谢谢@john我已经解决了这个问题
我觉得这很有趣,我只是从这些代码行中删除了“ _”
ViewState["lender_id"] = lenderid = Convert.ToInt32(Request.QueryString["lender_id"].ToString());
将lender_id
更改为lenderid