Showing posts with label reference. Show all posts
Showing posts with label reference. Show all posts

Saturday, March 24, 2012

newbie: runtime error

Hey
asp.net 2.0
When I run the code below I get a runtime error ("Object reference not set
to an instance of an object. "):
Here is the code:
public static ICollection getInbox()
{
ArrayList al = new ArrayList();
ConnectionStringSettings css =
ConfigurationManager.ConnectionStrings["aspnet_DB"];
SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
UserName from aspnet_Users");
try
{
IEnumerable INames = sds.Select(DataSourceSelectArguments.Empty);
foreach (DataRowView row in INames)
{
al.Add(row["UserName"]);
}
}
catch (SqlException sqlException)
{
Debug.WriteLine(sqlException.Message.ToString());
}
sds.Dispose();
return al;
}
The error occur at this line in the code:
SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
UserName from aspnet_Users");
Just in case here is my web.config file:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<add key="aspnet_DB" value="Data Source=.\\SQLEXPRESS;Integrated
Security=True;AttachDBFilename=|DataDire
ctory|aspnetdb.mdf;User
Instance=true" />
</appSettings>
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/>
<profile enabled="true">
<properties>
<add name="Picture" type="System.Byte[]" />
<add name="PictureType" type="string" />
</properties>
</profile>
</system.web>
</configuration>
Any ideas what I'm doing wrong here?
JeffJeff wrote:
> Hey
> asp.net 2.0
>
> When I run the code below I get a runtime error ("Object reference not set
> to an instance of an object. "):
> Here is the code:
> public static ICollection getInbox()
> {
> ArrayList al = new ArrayList();
> ConnectionStringSettings css =
> ConfigurationManager.ConnectionStrings["aspnet_DB"];
> SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
> UserName from aspnet_Users");
> try
> {
> IEnumerable INames = sds.Select(DataSourceSelectArguments.Empty);
> foreach (DataRowView row in INames)
> {
> al.Add(row["UserName"]);
> }
> }
> catch (SqlException sqlException)
> {
> Debug.WriteLine(sqlException.Message.ToString());
> }
> sds.Dispose();
> return al;
> }
> The error occur at this line in the code:
> SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
> UserName from aspnet_Users");
> Just in case here is my web.config file:
> <?xml version="1.0"?>
> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"
> <appSettings>
> <add key="aspnet_DB" value="Data Source=.\\SQLEXPRESS;Integrated
> Security=True;AttachDBFilename=|DataDire
ctory|aspnetdb.mdf;User
> Instance=true" />
> </appSettings>
> <system.web>
> <roleManager enabled="true"/>
> <authentication mode="Forms"/>
> <compilation debug="true"/>
> <profile enabled="true">
> <properties>
> <add name="Picture" type="System.Byte[]" />
> <add name="PictureType" type="string" />
> </properties>
> </profile>
> </system.web>
> </configuration>
> Any ideas what I'm doing wrong here?
> Jeff
Hi Jeff,
If looks like css is null. I'm guessing this is because there is no
<connectionStrings> in the web.config.
See http://www.devx.com/dotnet/Article/27562
David Hogue

newbie: runtime error

Hey

asp.net 2.0

When I run the code below I get a runtime error ("Object reference not set
to an instance of an object. "):

Here is the code:

public static ICollection getInbox()
{
ArrayList al = new ArrayList();
ConnectionStringSettings css =
ConfigurationManager.ConnectionStrings["aspnet_DB"];
SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
UserName from aspnet_Users");
try
{
IEnumerable INames = sds.Select(DataSourceSelectArguments.Empty);
foreach (DataRowView row in INames)
{
al.Add(row["UserName"]);
}
}
catch (SqlException sqlException)
{
Debug.WriteLine(sqlException.Message.ToString());
}
sds.Dispose();
return al;
}

The error occur at this line in the code:
SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
UserName from aspnet_Users");

Just in case here is my web.config file:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<add key="aspnet_DB" value="Data Source=.\\SQLEXPRESS;Integrated
Security=True;AttachDBFilename=|DataDirectory|aspn etdb.mdf;User
Instance=true" />
</appSettings>
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/>
<profile enabled="true">
<properties>
<add name="Picture" type="System.Byte[]" />
<add name="PictureType" type="string" />
</properties>
</profile>
</system.web>
</configuration>

Any ideas what I'm doing wrong here?

JeffJeff wrote:
> Hey
>
> asp.net 2.0
>
>
> When I run the code below I get a runtime error ("Object reference not set
> to an instance of an object. "):
>
> Here is the code:
>
> public static ICollection getInbox()
> {
> ArrayList al = new ArrayList();
> ConnectionStringSettings css =
> ConfigurationManager.ConnectionStrings["aspnet_DB"];
> SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
> UserName from aspnet_Users");
> try
> {
> IEnumerable INames = sds.Select(DataSourceSelectArguments.Empty);
> foreach (DataRowView row in INames)
> {
> al.Add(row["UserName"]);
> }
> }
> catch (SqlException sqlException)
> {
> Debug.WriteLine(sqlException.Message.ToString());
> }
> sds.Dispose();
> return al;
> }
>
> The error occur at this line in the code:
> SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
> UserName from aspnet_Users");
>
> Just in case here is my web.config file:
> <?xml version="1.0"?>
> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
> <appSettings>
> <add key="aspnet_DB" value="Data Source=.\\SQLEXPRESS;Integrated
> Security=True;AttachDBFilename=|DataDirectory|aspn etdb.mdf;User
> Instance=true" />
> </appSettings>
> <system.web>
> <roleManager enabled="true"/>
> <authentication mode="Forms"/>
> <compilation debug="true"/>
> <profile enabled="true">
> <properties>
> <add name="Picture" type="System.Byte[]" />
> <add name="PictureType" type="string" />
> </properties>
> </profile>
> </system.web>
> </configuration>
>
> Any ideas what I'm doing wrong here?
>
> Jeff

Hi Jeff,

If looks like css is null. I'm guessing this is because there is no
<connectionStrings> in the web.config.

See http://www.devx.com/dotnet/Article/27562
--
David Hogue

Thursday, March 22, 2012

Newby question: How do you handles arrays with functions?

Just some basic questions because none of my reference manuals cover
this explicitly:
1) If you want have an argument as an array of integers would this
be the correct declaration?
Function foo(bar() as Integer) as Integer
..
End Function
2) If you wanted to *return* an array of integers from the function
would this declaration be correct?
Function foo(bar as Integer) as Integer()
..
End Function
TIA...Blue Streak,
Yep, you've got it.
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Blue Streak" <rdlebreton@.hotmail.com> wrote in message
news:1134415138.256287.261280@.g44g2000cwa.googlegroups.com...
> Just some basic questions because none of my reference manuals cover
> this explicitly:
> 1) If you want have an argument as an array of integers would this
> be the correct declaration?
> Function foo(bar() as Integer) as Integer
> ...
> End Function
> 2) If you wanted to *return* an array of integers from the function
> would this declaration be correct?
> Function foo(bar as Integer) as Integer()
> ...
> End Function
> TIA...
>
Since you went to the trouble of writing it out here, you could have simply
tried it out. Your code looks fine, except I think () should come after
integer not bar in the 1st example
For the parameters, you could declare it as ParamArray which would let you
pass in 1 value, great replacement for overloading (in some cases)
Function foo (ParamArray bar as integer()
end function
you can now call foo with either a single value, or an array, or a comma
separated list
foo(1)
foo(arr)
foo(1,2,3,4,5)
ParramArray _must_ be the last parameter of a function.
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
"Blue Streak" <rdlebreton@.hotmail.com> wrote in message
news:1134415138.256287.261280@.g44g2000cwa.googlegroups.com...
> Just some basic questions because none of my reference manuals cover
> this explicitly:
> 1) If you want have an argument as an array of integers would this
> be the correct declaration?
> Function foo(bar() as Integer) as Integer
> ...
> End Function
> 2) If you wanted to *return* an array of integers from the function
> would this declaration be correct?
> Function foo(bar as Integer) as Integer()
> ...
> End Function
> TIA...
>
Karl,
In VB.NET the parentheses may be placed just after the parameter name or
after the type declaration. It's up to the developer, but both ways work.
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%23fDEHL1$FHA.316@.TK2MSFTNGP10.phx.gbl...
> Since you went to the trouble of writing it out here, you could have
> simply tried it out. Your code looks fine, except I think () should come
> after integer not bar in the 1st example
> For the parameters, you could declare it as ParamArray which would let
> you pass in 1 value, great replacement for overloading (in some cases)
> Function foo (ParamArray bar as integer()
> end function
> you can now call foo with either a single value, or an array, or a comma
> separated list
> foo(1)
> foo(arr)
> foo(1,2,3,4,5)
> ParramArray _must_ be the last parameter of a function.
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
> "Blue Streak" <rdlebreton@.hotmail.com> wrote in message
> news:1134415138.256287.261280@.g44g2000cwa.googlegroups.com...
>

Friday, March 16, 2012

News_view error

Why am I getting this error....Please help anyone

Robert

Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 18: Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)Line 19: Dim view As Data.DataRowView = CType(FormView1.DataItem, Data.DataRowView)Line 20: Dim o As Object = view.Item("staticURL")Line 21: If Not o Is Nothing AndAlso Not IsDBNull(o) ThenLine 22: 'We have a static URL, we need to redirect.


Source File:C:\Documents and Settings\Robert Rucker\My Documents\SwingSet Group, Inc\News_View.aspx Line:20

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] ASP.news_view_aspx.FormView1_DataBound(Object sender, EventArgs e) in C:\Documents and Settings\Robert Rucker\My Documents\SwingSet Group, Inc\News_View.aspx:20 System.Web.UI.WebControls.BaseDataBoundControl.OnDataBound(EventArgs e) +56 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +117 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +25 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +140 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +68 System.Web.UI.WebControls.FormView.DataBind() +5 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +61 System.Web.UI.WebControls.FormView.EnsureDataBound() +138 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +67 System.Web.UI.Control.EnsureChildControls() +97 System.Web.UI.Control.PreRenderRecursiveInternal() +50 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5684

FormView1.DataItem is Nothing and therefore access of the Item Property on nothing is "Object reference not set to an instance of an object"

Dim o As Object = view.Item("staticURL")


What should I do then...don't understand...should I change it?