private void BindGrid()
{
//int iPageSize = 0;
//int iRow = 0;
SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=Demo_eLogsVA4;Integrated Security=True");
cn.Open();
string q = "Select Convert(nVarchar,A.Rec_No) CRec,A.Acc_Name Descr,A.Quantity Qty,Convert(nVarchar,A.Sell_Rate) SRate,Sell_CName Sname , Sell_CCode SCCode, Sell_CValue SCValue ,Convert(numeric,A.Quantity*A.Sell_Rate*Sell_CValue) as SAmount, A.Service_Tax STax,Convert(nVarchar,(A.Quantity*A.Sell_Rate*Sell_CValue)* A.Service_Tax/100)Tax_Amount,Convert(numeric,((A.Quantity*A.Sell_Rate*Sell_CValue)+(A.Quantity*A.Sell_Rate*Sell_CValue)* A.Service_Tax/100)) as Net From eLogs_Invoice_Charges_Details A Where A.Invoice_Code='INV1'";
//string qq = "Select COUNT(*) From eLogs_Invoice_Charges_Details A Where A.Invoice_Code='INV1'";
DataSet dset = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(q, cn);
//DataTable dtable = new DataTable();
da.Fill(dtable);
GridView1.DataSource = dtable;
object obj = dtable.Compute("Sum(Net)", "");
object amt=dtable.Compute("Sum(SAmount)","");
decimal value=0;
if (obj != null)
{
value = (Decimal)obj;
}
else
{
// obj is null.
}
DataRow dr;
for (int i = dt.Rows.Count; i < 10; i++)
{
dr = dt.NewRow();
dr[0] = dr[1] = dr[2] = dr[3] = dr[4] = "";
dt.Rows.Add(dr);
}
dt.AcceptChanges();
//object obj = dtable.Compute("SUM(Net)", string.Empty);
//dtable.Rows.Add(new object[] { "", "" });
//dtable.Rows.Add(new object[] { "", "" });
GridView1.DataBind();
//iPageSize = Convert.ToInt32(GridView1.PageCount.ToString());
//iRow = Convert.ToInt32(GridView1.Rows.Count.ToString());
GridView1.FooterRow.Cells[1].Text = "Total:";
GridView1.FooterRow.Cells[7].Text = amt.ToString();
GridView1.FooterRow.Cells[10].Text = value.ToString();
//GridView1.FooterRow.Cells[2].Text = iRow.ToString();
//GridView1.FooterRow.Cells[3].Text = iPageSize.ToString();
GridView1.FooterStyle.Font.Bold = true;
cn.Close();
}
我在上面的代码中有错误。
未将对象引用设置到对象的实例。
说明:执行当前Web请求期间,出现未处理的异常。请检讨有关错误的更多信息,堆栈跟踪,它起源于代码。
异常详细信息:System.NullReferenceException:未将对象引用设置到对象的实例
源错误:
第50行:}
第51行:DataRow的博士;
第52行:(I = dt.Rows.Count;我<10;我)
第53行:{
第54行:博士= dt.NewRow(); 这个循环的目的是插入一个空白行,如果页地址到网格视图pagerows的不等于