An exception of type 'System.ArgumentNullException' occurred in System.Data.dll was not handled in user code Additional information: The 'dataType' argument can not be null.


Hi, I am getting an exeption

An exception of type 'System.ArgumentNullException' occurred in System.Data.dll was not handled in user code Additional information: The 'dataType' argument can not be null.

When executing the below code

[HttpPost]
public JsonResult Chart()
{
string constr = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("select text,date from T"))
{
cmd.Connection = con;
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
//Create a new DataTable.
DataTable dt = new DataTable("T");
List<object> iData = new List<object>();
//Load DataReader into the DataTable.
// dt.Load(sdr);
dt.Columns.Add(sdr["text"].ToString(), System.Type.GetType("System.String"));
dt.Columns.Add(sdr["date"].ToString(), System.Type.GetType("System.Datetime"));

foreach (DataColumn dc in dt.Columns)
{
List<object> x = new List<object>();
x = (from DataRow drr in dt.Rows select drr[dc.ColumnName]).ToList();
iData.Add(x);

}
//Source data returned as JSON
return Json(iData, JsonRequestBehavior.AllowGet);

}
}

}

Here is the image of the error

How can I resolve it? thanks.


Asked by:- LuneAgile
0
: 2106 At:- 8/8/2018 11:43:29 AM
ASP.NET ArgumentNullException







2 Answers
profileImage Answered by:- vikas_jk

You are passing NULL data in this line of the code

dt.Columns.Add(sdr["date"].ToString(), System.Type.GetType("System.Datetime"));

sdr["date"] should not be passed as Null value in the above code, always check if values are null or not and then execute this statement.

1
At:- 8/8/2018 4:11:00 PM


profileImage Answered by:- LuneAgile

Thanks vikas

0
At:- 8/8/2018 6:00:38 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use