My Controller, Model and View are as follows. I get the error in the subject. I am new in this stuff and need some help. Do anyone has any idea on how can I solve the problem?
Thanks...
Controller:
namespace RIMBochumDBv6.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
string connStr = "data source=myDataSource;Initial Catalog=myDb;Integrated Security=True";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECT UNIT_ID,IDTYP_CD,UPD_DATE FROM XID", conn);
DataSet ds = new DataSet();
da.Fill(ds);
List<string> Lst = (from m in ds.Tables["Default"].AsEnumerable() select m.Field<long>("UNIT_ID") + m.Field<string>("IDTYP_CD") + m.Field<DateTime>("UPD_DATE")).ToList();
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
return View(Lst);
}
}
}
Model:
namespace RIMBochumDBv6.Models
{
public class DbModel
{
public long unitId { get; set; }
I get the error ar :List<string> Lst = (from m in ds.Tables["Default"].AsEnumerable() select m.Field<long>("UNIT_ID") + m.Field<string>("IDTYP_CD") + m.Field<DateTime>("UPD_DATE")).ToList();
Sorry for verdancy, I have solved the problem. Actualy I have changed my way. I removed the model, instead I created LINQ to SQL + used ViewBag to show the results and also used some scripts to show the results of the query in the view...
obenkadir
Member
47 Points
32 Posts
Arror: "ArgumentNullException was undandled by user code. Value cannot be null."
Feb 07, 2012 01:27 PM|LINK
Hi,
My Controller, Model and View are as follows. I get the error in the subject. I am new in this stuff and need some help. Do anyone has any idea on how can I solve the problem?
Thanks...
Controller:
namespace RIMBochumDBv6.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
string connStr = "data source=myDataSource;Initial Catalog=myDb;Integrated Security=True";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECT UNIT_ID,IDTYP_CD,UPD_DATE FROM XID", conn);
DataSet ds = new DataSet();
da.Fill(ds);
List<string> Lst = (from m in ds.Tables["Default"].AsEnumerable() select m.Field<long>("UNIT_ID") + m.Field<string>("IDTYP_CD") + m.Field<DateTime>("UPD_DATE")).ToList();
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
return View(Lst);
}
}
}
Model:
namespace RIMBochumDBv6.Models
{
public class DbModel
{
public long unitId { get; set; }
public string idtypCD { get; set; }
public DateTime updDate { get; set; }
}
}
View:
@model IEnumerable<RIMBochumDBv6.Models.DbModel>
@{
ViewBag.Title = "Index";
}
<table>
<tr>
<th>
unitId
</th>
<th>
idtypCD
</th>
<th>
updDate
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.unitId)
</td>
<td>
@Html.DisplayFor(modelItem => item.idtypCD)
</td>
<td>
@Html.DisplayFor(modelItem => item.updDate)
</td>
</tr>
}
</table>
raduenuca
All-Star
24675 Points
4250 Posts
Re: Arror: "ArgumentNullException was undandled by user code. Value cannot be null."
Feb 07, 2012 01:30 PM|LINK
which line gives you the error? you may be new to ths "stuff" called ASP.NET MVC but also on debugging?!?
Radu Enuca | Blog
obenkadir
Member
47 Points
32 Posts
Re: Arror: "ArgumentNullException was undandled by user code. Value cannot be null."
Feb 07, 2012 01:32 PM|LINK
You are right.
I get the error ar :List<string> Lst = (from m in ds.Tables["Default"].AsEnumerable() select m.Field<long>("UNIT_ID") + m.Field<string>("IDTYP_CD") + m.Field<DateTime>("UPD_DATE")).ToList();
raduenuca
All-Star
24675 Points
4250 Posts
Re: Arror: "ArgumentNullException was undandled by user code. Value cannot be null."
Feb 07, 2012 01:46 PM|LINK
1. Do you have a table called Default? Check the ds.Tables
2. Are there any values in it?
Radu Enuca | Blog
obenkadir
Member
47 Points
32 Posts
Re: Arror: "ArgumentNullException was undandled by user code. Value cannot be null."
Feb 07, 2012 01:50 PM|LINK
Yes, i have the table in my db and the table also has many records in it.
raduenuca
All-Star
24675 Points
4250 Posts
Re: Arror: "ArgumentNullException was undandled by user code. Value cannot be null."
Feb 07, 2012 02:22 PM|LINK
not in the DB...in the ds object
Radu Enuca | Blog
Young Yang -...
All-Star
21344 Points
1818 Posts
Microsoft
Re: Arror: "ArgumentNullException was undandled by user code. Value cannot be null."
Feb 09, 2012 09:08 AM|LINK
Hi
There is no "Dsfault" table for the dataset, you should define it.
Hope this helpful
Regards
Young Yang
Feedback to us
Develop and promote your apps in Windows Store
obenkadir
Member
47 Points
32 Posts
Re: Arror: "ArgumentNullException was undandled by user code. Value cannot be null."
Feb 09, 2012 10:58 AM|LINK
Hi,
Sorry for verdancy, I have solved the problem. Actualy I have changed my way. I removed the model, instead I created LINQ to SQL + used ViewBag to show the results and also used some scripts to show the results of the query in the view...
Thanks both of you for the help.