对象referance未设置为对象的实例 [英] Object referance not set to an instance of an object
本文介绍了对象referance未设置为对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void GridDataSave()
{
foreach (GridViewRow s in grdqutotation.Rows)
{
////TextBox id = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_id");
//TextBox srno = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_srno");
//TextBox description = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_desc");
//TextBox Quantity = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_Qty");
//TextBox Units = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_Unit");
//TextBox Rate = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_Rate");
//TextBox Amount = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_amount");
Tbl_SubFinalQuotation a = new Tbl_SubFinalQuotation();
//// TextBox id = (TextBox)s.FindControl("txt_id");
a.Quto_No = txtQno.Text;
////a.id = Convert.ToInt32(s.Cells[0].Text);
TextBox srno = (TextBox)s.FindControl("txt_srno");
//Decimal p = Convert.ToDecimal((srno.Text));
TextBox description = (TextBox)s.FindControl("txt_desc");
// string q = description.Text;
TextBox Quantity = (TextBox)s.FindControl("txt_Qty");
//Decimal r = Convert.ToDecimal((Quantity.Text));
TextBox Units = (TextBox)s.FindControl("txt_Unit");
// string t = Units.Text;
TextBox Rate = (TextBox)s.FindControl("txt_Rate");
// Decimal u = Convert.ToDecimal((Rate.Text));
TextBox Amount = (TextBox)s.FindControl("txt_amount");
// Decimal v = Convert.ToDecimal((Amount.Text));
a.srno = Convert.ToDecimal (srno.Text );
a.productName = description .Text ;
a.Quantity = Convert.ToDecimal (Quantity .Text );
a.Units = Units .Text ;
a.Rate = Convert.ToDecimal (Rate .Text );
a.Amount = Convert.ToDecimal (Amount .Text );
context.Tbl_SubFinalQuotations.InsertOnSubmit(a);
context.SubmitChanges();
a = null;
}
}
我的尝试:
What I have tried:
private void GridDataSave()
{
foreach (GridViewRow s in grdqutotation.Rows)
{
////TextBox id = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_id");
//TextBox srno = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_srno");
//TextBox description = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_desc");
//TextBox Quantity = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_Qty");
//TextBox Units = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_Unit");
//TextBox Rate = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_Rate");
//TextBox Amount = (TextBox)grdqutotation.Rows[s.RowIndex].FindControl("txt_amount");
Tbl_SubFinalQuotation a = new Tbl_SubFinalQuotation();
//// TextBox id = (TextBox)s.FindControl("txt_id");
a.Quto_No = txtQno.Text;
////a.id = Convert.ToInt32(s.Cells[0].Text);
TextBox srno = (TextBox)s.FindControl("txt_srno");
//Decimal p = Convert.ToDecimal((srno.Text));
TextBox description = (TextBox)s.FindControl("txt_desc");
// string q = description.Text;
TextBox Quantity = (TextBox)s.FindControl("txt_Qty");
//Decimal r = Convert.ToDecimal((Quantity.Text));
TextBox Units = (TextBox)s.FindControl("txt_Unit");
// string t = Units.Text;
TextBox Rate = (TextBox)s.FindControl("txt_Rate");
// Decimal u = Convert.ToDecimal((Rate.Text));
TextBox Amount = (TextBox)s.FindControl("txt_amount");
// Decimal v = Convert.ToDecimal((Amount.Text));
a.srno = Convert.ToDecimal (srno.Text );
a.productName = description .Text ;
a.Quantity = Convert.ToDecimal (Quantity .Text );
a.Units = Units .Text ;
a.Rate = Convert.ToDecimal (Rate .Text );
a.Amount = Convert.ToDecimal (Amount .Text );
context.Tbl_SubFinalQuotations.InsertOnSubmit(a);
context.SubmitChanges();
a = null;
}
}
推荐答案
在调试器中运行代码,Visual Studio将停在违规行上,将鼠标移到该行上并在工具提示中查看哪个对象 null
。
Run your code in the debugger, Visual Studio will stop on the offending line, move your mouse over the line and see in the tool tips which object is null
.
这篇关于对象referance未设置为对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文