Hi My Static Method
[WebMethod(EnableSession = true)]
public static List<Entity.Report> ChartNavigation(string type, string user, string date)
{
WebForm2 objForm = new WebForm2();
objForm.BindCVTrackerForNavigation(user, date);
List<Entity.Report> listchart = new List<Entity.Report>();
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Recruitment"].ConnectionString))
{
string sqlString = "GetNumberOfCVSentForChartNavigation";
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@UserName", user.Replace("\"", "")));
cmd.Parameters.Add(new SqlParameter("@Date", date.Replace("\"", "")));
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (rdr.Read())
{
Entity.Report obj = new Entity.Report();
Utilities.Common.Fill(obj, rdr);
listchart.Add(obj);
}
conn.Close();
}
}
return listchart;
}
我从中调用非静态方法。我的非静态方法是
protected void BindCVTrackerForNavigation(string User,string Date)
{
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Recruitment"].ConnectionString))
{
string sqlString = "GetNumberOfCVSentForNavigation";
using (SqlCommand cmd = new SqlCommand(sqlString, conn))
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@UserName", User.Replace("\"", "")));
cmd.Parameters.Add(new SqlParameter("@Date", Date.Replace("\"", "")));
conn.Open();
SqlDataAdapter DA1 = new SqlDataAdapter(cmd);
DA1.Fill(ds);
conn.Close();
}
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
gvCVTracker.DataSource = ds.Tables[0];
gvCVTracker.DataBind();
}
}
}
}
当数据源应用于gvCVTracker
时,它会抛出错误Object reference not set to an instance of an object.
我不知道是什么问题?任何帮助都会受到欢迎。谢谢。
答案 0 :(得分:0)
您必须使用Page.LoadControl为它创建一个WebForm2实例,以便处理控件的初始化。