single teir with SQL compact database (SQLCe) Erro with data_fetchsingle teir with SQL compact database (SQLCe) Erro with data_fetch
Old forum URL: forums.lhotka.net/forums/t/6558.aspx
sanbrar posted on Wednesday, March 04, 2009
Hello,
I am new to CSLA, please be nice.
I am working on a prototype following example in the book "C# 2005 Business Objects". Prototype very simple: only have employees and employees can multiple addresses. (Win Forms only)
After developing the business objects (employee, employee list, employee info, employee addresses, addresses) and UI, I get an error on using command in Data fetch in employee business object.
p = new SqlCeParameter("@param_ID", SqlDbType.NVarChar);
p.Value = criteria.Id.ToString();
cm.Parameters.Add(p);
using (SqlCeCommand cm = cn.CreateCommand())
{
Error: "System.NullreferenceException: Object reference not set to an instance of an object at Demo.Library.Employee.DataPortal_Fetch(Criteria criteria) in....
Can anyone please direct me in a right direction on how I can resolve this error. Any help or comments would be greatly appreciated.
Thanks,
San
rsbaker0 replied on Thursday, March 05, 2009
Hmmm. I'd think the error stack trace (and debugger) would tell you which line the problem occurred on, but I see two possible candidates here:
1. Does your criteria parameter have a value? If not, critieria.Id would cause and error.
2. You are referencing cm.Parameter. Does cm have a value at this point?
richardb replied on Thursday, March 05, 2009
You are referencing the cm object before it has been declared.
Add the parameter to the cm object
Using (SqlCeCommand cm = cn.CreateCommand()
{
cm.Parameters.Add(p)
etc.......
Copyright (c) Marimer LLC