Showing posts with label exception. Show all posts
Showing posts with label exception. Show all posts

Thursday, March 29, 2012

Object Null Reference Exception (vb)

Can someone tell me what this compiler error means?
Using VS.NET 2002/VB

----------------
Dim objFIF As New RMClassLib.FtInFr()

objFIF.CreateNewFIF(False, False, 3, 24)

pitchInDrp.DataSource = objFIF.GetNewFIF

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

Line 133: Dim objFIF As New RMClassLib.FtInFr()
-----------------

Thanks,
GeorgeIgnore that request for help. I think I have it figured out.

Thanks.
George

"George" <--@.--.--> wrote in message
news:4L0Sb.30723$6O4.823971@.bgtnsc04-news.ops.worldnet.att.net...
> Can someone tell me what this compiler error means?
> Using VS.NET 2002/VB
> ----------------
> Dim objFIF As New RMClassLib.FtInFr()
> objFIF.CreateNewFIF(False, False, 3, 24)
> pitchInDrp.DataSource = objFIF.GetNewFIF
> Exception Details: System.NullReferenceException: Object reference not set
> to an instance of an object.
> Line 133: Dim objFIF As New RMClassLib.FtInFr()
> -----------------
> Thanks,
> George

Object reference

Object reference not set to an instance of an object.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

Line 40: dtagrdReviewDisplay.DataBind();Line 41: //dropdownlistLine 42: drpdwnRevRating.Items[0].Selected=true;Line 43: drpdwnProRating.Items[0].Selected=true;Line 44:

Is there anything loaded into the dropDown?

You may want to make your code like this to prevent the error:

if(drpdwnRevRating.Items.Count > 0)

drpdwnRevRating.Items[0].Selected = true;

if(drpdwnProRating.Items.Count > 0)

drpdwnProRating.Items[0].Selected = true;


the rating dropdown has ratings 1 to 10,Autopostback property is set to true.

so when the user selects the rating,the new rating is shown in the label and when the forms reloads i want to make Select one as the item to be diplayed.


How about trying the code I sent just to get the page to load. Then you can see if there is actually anything in your dropdownlist. I tried to recreate your error and the only way I can is if I don't put anything into the dropdownlist.

Let me know what happens when you try those 'if' statements.


i have datagrid ,in datagrid i have one drop down,this dropdown has 1 to 10 as listitems

i want to catch the rating what the user has selected so

.aspx

<asp:DropDownList id="drpdwnRevRating" AutoPostBack="True" Runat="server">
<asp:ListItem Selected="True" Value="Select One">Select One</asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem Value="6">6</asp:ListItem>
<asp:ListItem Value="7">7</asp:ListItem>
<asp:ListItem Value="8">8</asp:ListItem>
<asp:ListItem Value="9">9</asp:ListItem>
<asp:ListItem Value="10">10</asp:ListItem>
</asp:DropDownList>
<br>
Rate the Product:
<asp:DropDownList>
<asp:ListItem Value="1">1</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>

.cs

privatevoid dtagrdReviewDisplay_SelectedIndexChanged(object sender, System.EventArgs e)

{

string strRevRating;

strRevRating=Request["drpdwnRevRating"];

Response.Write(strRevRating);

}

Output notthing is coming in strRevRating and i used break point here,the comilation is not coming into this eventhandler itself.


is their is any problem in this event handler of dropdownlist control what i wrote

protected System.Web.UI.WebControls.DropDownList drpdwnRevRating;

this.drpdwnRevRating.SelectedIndexChanged += new System.EventHandler(this.drpdwnRevRating_SelectedIndexChanged);


private void drpdwnRevRating_SelectedIndexChanged(object sender, System.EventArgs e)
{
string strRevRating;
strRevRating=Request["drpdwnRevRating"];
Response.Write(strRevRating);

}

Object reference not set to an instance of an object.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

Line 65: { Line 66: this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);Line 67: this.drpdwnRevRating.SelectedIndexChanged += new System.EventHandler(this.drpdwnRevRating_SelectedIndexChanged);Line 68: this.Load += new System.EventHandler(this.Page_Load);Line 69:


I think the issues you are having is because the DropDownList does not belong to the page, it belongs to the datagrid. The null exception is because there is no "this.drpdwnRevRating".

To work with the dropdownlists, you must find the control on the line of the datagrid and cast it to a DropDownList. I assume you are using ASP.Net 1.1 which I don't have installed on this computer or I would type up a quick sample, but you can refer to this article.http://www.codeproject.com/aspnet/DataGridDropDownList.asp

Pay attention to how they are doing:

DropDownList dl = (DropDownList)(dgi.Cells[2].Controls[1]);

You can also do:

DropDownList dl = (DropDownList)(dgi.Rows[e.SelectedIndex].FindControls("drpdwnProRating");

//I think that is the right syntax but I don't have the luxury of intellisense right now.

Then you can work with 'dl' instead of 'drpdwnProRating'

I hope that helps to move your forward a bit.

Monday, March 26, 2012

Object reference not being returned

I have two functions, one calls the other. I haven't been able to figure out why I am getting nothing returned. The exception is thrown on the objCommand.ExecuteNonQuery() Thanks for looking

Dave

First Function

Sub AddNewUser()

Dim objUserFunctions As UserFunctions = New UserFunctions()
Dim objUserInfo As UserInfo = New UserInfo()
Dim objProviderFunctions As ProviderFunctions = New ProviderFunctions()
Dim objProviderInfo As ProviderInfo = New ProviderInfo()

objProviderInfo = objProviderFunctions.GetProviderID(txtProviderName.Text)
objUserInfo = objUserFunctions.PasswordGen(txtProviderName.Text, txtProviderContactName.Text)

objUserFunctions.AddUser(txtProviderEmail.Text, objUserInfo.UserPassword, txtProviderContactName.Text, objProviderInfo.ProviderID, 0)

End Sub

Second Function

Public Function GetProviderID(ByVal ProviderName As String) As ProviderInfo
Dim objConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim objCommand As SqlCommand = New SqlCommand("GetProviderID", objConnection)
Dim objProviderInfo As ProviderInfo = New ProviderInfo()

Dim parameterProviderName As SqlParameter = New SqlParameter("@dotnet.itags.org.ProviderName", SqlDbType.NVarChar, 100)
Dim parameterProviderID As SqlParameter = New SqlParameter("@dotnet.itags.org.ProviderID", SqlDbType.Int, 4)

Try
'MARK COMMAND AS STORED PROCEDURE
objCommand.CommandType = CommandType.StoredProcedure

'INPUT PARAMETERS
parameterProviderName.Value = ProviderName
objCommand.Parameters.Add(parameterProviderName)

'OUTPUT PARAMETERS
parameterProviderID.Direction = ParameterDirection.Output
objCommand.Parameters.Add(parameterProviderID)

'OPEN THE CONNECTION AND EXECUTE THE COMMAND
objConnection.Open()
objCommand.ExecuteNonQuery()
objConnection.Close()

objProviderInfo.ProviderID = parameterProviderID.Value

GetProviderID = objProviderInfo

Catch e As Exception
Console.WriteLine()
Console.WriteLine()
Console.WriteLine("The following exception occured:")
Console.WriteLine("Exception : " + e.ToString())
Console.WriteLine("Message : " + e.Message)
Console.WriteLine("StackTrace : " + e.StackTrace)

Finally
objConnection = Nothing
objCommand = Nothing
objProviderInfo = Nothing
parameterProviderName = Nothing
parameterProviderID = Nothing

End Try

End FunctionCan you please post the complete output of those lines:

Console.WriteLine("The following exception occured:")
Console.WriteLine("Exception : " + e.ToString())
Console.WriteLine("Message : " + e.Message)
Console.WriteLine("StackTrace : " + e.StackTrace)

For now, I can't see any errors in your code.
I already fixed it, it was a damn error in my sproc. Thanks anyway!

Object reference not set

Hi, the exception "Object reference not set to an instance of an object", was thrown when I run my code.

If Not IsPostBack Then

Dim DBConn As OdbcConnection
Dim DBCommand As OdbcDataAdapter
Dim i As Integer

For i = 0 To CarNamesDL.Items.Count - 1
If CarNamesDL.Items(i).Selected Then
DBConn = New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=CarCompaniesDB;User=root;Password=soukpass;Option=3;")
DBCommand = New OdbcDataAdapter("SELECT CarID, Model From CarCompaniesDB where Make = '" & CarNamesDL.Items(i).Text & "'", DBConn)
Else : Exit For
End If
Next

DBCommand.Fill(DS, "CarCompaniesDB")

CarNamesDL.DataSource = DS.Tables("CarCompaniesDB").DefaultView

CarNamesDL.DataBind()

End If

This is the Source error:

Line 43: End If
Line 44: Next
Line 45: DBCommand.Fill(DS, "CarCompaniesDB")
Line 46:
Line 47: CarNames.DataSource = DS.Tables("CarCompaniesDB").DefaultView

I don't know what could be causing this. I don't think its because of notdeclaring a variable before its use 'cause I've checked. I'm not sureif its bad scoping, I've also made sure to Exit the For Loop

in the Else clause in case no match was found. Please take a look to see if my code is missing something or if it is incorrect, thank you in advance for yourhelp.

Hi,

Is your DS anywhere declared and new DataSet created and assigned to DS?

Even if your DS is declared somewhere else or not declared at all, you need to create new DataSet and assign it to DS variable.

DS = New DataSet()

-yuriy


please post complete post.

I dont see that you have initialize any where the "DS" that is DataSet.


Hi, thanks for your reply my code now sort of works but it still has a little problem. The following is my modified code:

If Not IsPostBack Then

Dim DBConn As OdbcConnection
Dim DBCommand As OdbcCommand
Dim i As Integer
Dim DS As New DataSet
For i = 0 To CarNamesDL.Items.Count - 1
If CarNamesDL.Items(i).Selected Then
DBConn = New OdbcConnection("Driver={MySQL ODBC 3.51Driver};Server=myServer;Database=CarCompaniesDB;User=myUser;Password=myPass;Option=3;")
DBCommand = New OdbcCommand("SELECT CarID, Model From CarCompaniesDBwhere Make = '" & CarNamesDL.Items(i).Text & "'", DBConn)

End If
Next
If Not IsNothing(DBConn) Then
DBConn.Open()
DBCommand.Connection = DBConn
Dim AD As New OdbcDataAdapter(DBCommand)

AD.Fill(DS, "CarCompaniesDB")
Me.CarNamesDL.DataTextField = "CarID"
Me.CarNamesDL.DataValueField = "Model"

CarNamesDL.DataBind()

End If
End If

Thisis the code for the button used to display the result, I don't quiteunderstand it since doing something different than what the MSDN saysits suppose to do.

Private Sub Bt_OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt_OK.Click
lblDataSelected.Text = "Selected Text: " &CarNamesDL.SelectedItem.Text & "<BR> Selected Value: " &CarNamesDL.SelectedValue & "<BR> Selected Index: " &CarNamesDL.SelectedIndex
End Sub

How do I get it to display make "Model" and not just the listitem when a user selects a listitem? Thank you for your help.

object reference not set to an instance of an object

I'm getting the following error:

Object reference not set to an instance of an object.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

I have trace on, but still I'm having trouble detereming what exactly is wrong. Is there anything else you could recommend trying to do? I'm using a dll that was created by a former co-worker and I'm not exactly sure how it works, but trying to figure it out. Thanks

There are several reasons for this. But we are going to need more information. Could you narrow it down to at least where this is happening and posting the code?


If your having trouble finding it, make sure the dll is compiled in debug mode. Also you may want to enable breaking on all exceptions: In the debug menu select 'Exceptions' and check all the boxes under 'Thrown' then click ok and try debugging again. This way if the error is trapped, you'll still break on the line that through the exception.


Why not step through the code to see exactly where it's kicking out. This is a general error that occurs when an object is trying to be referenced that has not been instantiated. Like the other posters eluded to, this can happen in many places. Put some code up for more help.


try to use a breakpoints and see at which line exception is being threw and we can check the line.

Object reference not set to an instance of an object

Hi, the following code generates the exception "Object reference not set to an instance of an object" when viewed in the browser. I have read that the most common causesof this error are not declaring the variables before usingthem, bad scoping, and not using the key word New wheninstantiating. I thought I have made sure that the afore mentionedcauses are not the causes of the error I'm getting but obviously thereis something wrong with my code. Please help me identify thecause of the exception, I just can not see what it could be at themoment. Thank you in advance for your help.

Dim myCon As OdbcConnection
Dim i As Integer
Dim cmd As OdbcCommand
For i = 0 To ListBox2.Items.Count - 1
If ListBox2.Items(i).Selected Then

myCon = New OdbcConnection("Driver={MySQL ODBC 3.51Driver};Server=myServer;Database=myDatabase;User=myUser;Password=myPW;Option=3;")
cmd = New OdbcCommand("SELECT * FROM myTable where Professions = '"& ListBox2.Items(i).Text & "'")

End If
Next
myCon.Open()

cmd.Connection = myCon

Dim ds As New DataSet

Dim ad As New OdbcDataAdapter(cmd)

ad.Fill(ds)

Me.ListBox2.DataSource = ds

Me.ListBox2.DataTextField = "Professions"

Me.ListBox2.DataBind()

try changing to:

Dim myCon As new OdbcConnection(yourConnectionString)
Dim cmd As new OdbcCommand(yourQuery)


For i = 0 To ListBox2.Items.Count - 1
If ListBox2.Items(i).Selected Then

myCon = New OdbcConnection("Driver={MySQL ODBC 3.51Driver};Server=myServer;Database=myDatabase;User=myUser;Password=myPW;Option=3;")
cmd = New OdbcCommand("SELECT * FROM myTable where Professions = '" & ListBox2.Items(i).Text & "'")

End If
Next

[If no item is selected is selected in the ListBox2, then myCon will be a null value, so what you need to do is to make sure myCon is checked against this situation before calling the open function.

Something like

If myCon is Not Nothing (I am not a vb guru, but you get the idea).
myCon.Open()

Saturday, March 24, 2012

object reference not set to an instance of an object

I keep on getting this error

Server Error in '/' Application.

Object reference not set to an instance of an object.

Description:Anunhandled exception occurred during the execution of the current webrequest. Please review the stack trace for more information about theerror and where it originated in the code.
Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:

Line 30: dim stremail as string = "markmil2002@dotnet.itags.org.yahoo.com"
Line 31:
Line 32: intid = objpass.retrieveuserid(tbEmail.text)
Line 33:
Line 34: If intID = 0 Then


Source File:c:\inetpub\wwwroot\Forgot.aspx Line:32
Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
ASP.forgot_aspx.retrievePass(Object sender, EventArgs e) in c:\inetpub\wwwroot\Forgot.aspx:32
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277



Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
AndI know it means that tbemail isnt declared, but it is, I have arunat="server" in the tag as shown below in my code. So am Iwrong about something?

<Code>
<%@dotnet.itags.org. Page Language="vb" debug="true" %>
<%@dotnet.itags.org. Register TagPrefix="LCPL" Tagname="Header" src="http://pics.10026.com/?src=header.ascx" %>
<%@dotnet.itags.org. Register TagPrefix="LCPL" Tagname="Footer" src="http://pics.10026.com/?src=Footer.ascx" %>
<%@dotnet.itags.org. Import Namespace="System" %>
<%@dotnet.itags.org. Import Namespace="System.data" %>
<%@dotnet.itags.org. Import Namespace="System.data.oledb" %>

<script runat="server">
Sub Page_Load(sender as object, e as eventargs)


End SUb

Private Function sendnonMail(byVal fromAccount As String, ByVal toAccount as String, byVal title as String, byVal msg As String)
Dim mm as New system.Web.Mail.MailMessage()
mm.to = toAccount

mm.From = FRomAccount
mm.body = msg
mm.bodyFormat = System.Web.Mail.MailFormat.text
System.Web.Mail.SmtpMail.SmtpServer = "smtp-server.hawaii.rr.com"
System.Web.Mail.SmtpMail.Send(mm)

End Function

Sub retrievePass(sender as object, e as eventargs)
dim objpassworddetails as lcpl.passworddetails
dim objPass as lcpl.passwordretrieve
dim intid as integer
dim stremail as string = "markmil2002@dotnet.itags.org.yahoo.com"

intid = objpass.retrieveuserid(tbEmail.text)

If intID = 0 Then
lblMessage.Text = "<font color='red'>Invalid email address</Font>"
Else
dim strusername as string = objpass.retrieveusername(intID)
dim strPassword as string = objPass.retrievepassword(strusername, intid)

Dim toAccount as String
Dim FromAccount as String
Dim Title As String
Dim msg as String

Title = "username and Password "
msg = "Username: " & strusername & " Password: " & strpassword
fromAccount = "lcplunderground@dotnet.itags.org.gumballmail.com"
toAccount = tbEmail.Text


Call sendnonmail(fromAccount, toAccount, title, msg)

response.redirect("login.aspx?pass=1&email=" & tbemail.text)

End If

End Sub
</script>

<HTML>
<HEAD>
<LINK rel="stylesheet" type="text/css" name="Style" href="http://links.10026.com/?link=css.css">
<TITLE>
</TITLE>
</HEAD>
<BODY>
<LCPL:Header runat="server" />
<form runat = "server">
<table align="center" colspan="2">
<tr>
<td colspan="2" align="Center"><asp:label id="lblMEssage" runat="server" />
<tr>
<td><asp:label id="lblemail" text="E-mail address" runat="server" />
</td>
<td><asp:textbox id="tbEmail" text="" runat="server" />
</td>
</tr>
<tr>
<td colspan="2" Align="right">
<asp:button id="btnsubmit" Text="Retrieve Password" onclick="retrievePass" runat="server" />
</td>
</tr>
</table>
</Form>

</BODY>
<LCPL:footer runat="server" />
</HTML>
</code>
And here is my code behind
<Code>
Imports system
Imports System.Data
Imports System.Data.Oledb

Namespace LCPL
Public class passwordretrieve
PrivateobjConn as new oledbConnection("Provider=sqloledb;DataSource=MICROSOF-54052B\cpl;Initial Catalog=user;User Id=sa;Password=")

Public Function retrieveuserid(email as String) as integer
dim intid as integer
Dim objcmd as new oledbCommand("SpgetUserID", objConn)
objcmd.CommandType = Commandtype.StoredProcedure

Dim objParam as New oledbParameter("@dotnet.itags.org.email", oledbtype.BigInt)
objParam.Value = email
ObjCmd.Parameters.Add(objParam)


Try
objConn.Open
intID = objCmd.ExecuteScalar
objConn.Close
Catch e as Exception
throw e
End Try

if intid.ToString = "" Then
return 0
end if
Return intid


End Function


Public Function retrieveusername(userid as string) as string
dim strusername as string
Dim objcmd as new oledbCommand("SpgetUserID", objConn)
objcmd.CommandType = Commandtype.StoredProcedure

Dim objParam as New oledbParameter("@dotnet.itags.org.userid", oledbtype.varChar)
objParam.Value = userid
ObjCmd.Parameters.Add(objParam)


Try
objConn.Open
strusername = objCmd.ExecuteScalar
objConn.Close
Catch e as Exception
throw e
End Try


Return strusername


End Function

Public Function retrievepassword(username as string, userid as string) as string
dim strpassword as string
Dim objcmd as new oledbCommand("SpgetUserID", objConn)
objcmd.CommandType = Commandtype.StoredProcedure

Dim objParam as New oledbParameter("@dotnet.itags.org.userid", oledbtype.varChar)
objParam.Value = userid
ObjCmd.Parameters.Add(objParam)

objParam = new oledbParameter("@dotnet.itags.org.username", oledbType.varChar)
objParam.Value = username
objcmd.Parameters.add(objParam)

Try
objConn.Open
strpassword = objCmd.ExecuteScalar
objConn.Close
Catch e as Exception
throw e
End Try


Return strpassword


End Function

End Class
end namespace
</code>

markmil2002 wrote:

AndI know it means that tbemail isnt declared, but it is, I have arunat="server" in the tag as shown below in my code. So am Iwrong about something?

That is not the object that is the problem. Have a look at this part of your code:
dim objpassworddetails as lcpl.passworddetails
dim objPass as lcpl.passwordretrieve
dim intid as integer
dim stremail as string = "markmil2002@.yahoo.com"
intid = objpass.retrieveuserid(tbEmail.text)
You have defined objPass as being of type lcpl.passwordretrieve, but youhave never actually created an instance of this type. To fix this, youwill need to add a line similar to the following:
dim objpassworddetails as lcpl.passworddetails
dim objPass as lcpl.passwordretrieve
objPass = New lcpl.passwordretrieve()
dim intid as integer
dim stremail as string = "markmil2002@.yahoo.com"
intid = objpass.retrieveuserid(tbEmail.text)
That extra line may work as is, or it may not. It depends on how yourpasswordretrieve class is constructed. If you don't know what I mean bythat, please ask.


Well I tried your suggestion, and although it made sense to me, and sounded like a good idea, it did not work, so back to the drawing board I guess, lol.
For the sake of debugging, try this code:
dim objpassworddetails as lcpl.passworddetails
dim objPass as lcpl.passwordretrieve
objPass = New lcpl.passwordretrieve()
dim intid as integer
dim stremail as string = "markmil2002@.yahoo.com"
If objPass Is Nothing Then
Response.Write("objPass is Nothing.")
Response.End()
Else If tbEmail Is Nothing Then
Response.Write("tbEmail is Nothing.")
Respoonse.End()
Else
Response.Write("objPass and tbEmail both valid.")
Try
intid = objpass.retrieveuserid(tbEmail.text)
Response.Write("Assignment of intid succeeded.")
Catch
Response.Write("Assignment of intid failed.")
End Try
Response.End()
End If
Request this page through your browser, and see which response you get. You can then pinpoint the problem.

Thursday, March 22, 2012

Object reference not set to an instance of an object error

Hey again,

I'm getting this error for my calendar.aspx page.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

The source of the error is here:


ArrayList aEvents = new ArrayList();
--> foreach (DataRow zRow in ds.Tables["events"].Rows) <--
{
DateTime compareDate = GetSafeDate(zRow["UNIT_EVENT_DATE"].ToString());
if (compareDate == d)

Any ideas how to solve this?

Cheers,
Evil Shirt NinjaEither ds is null, or it doesn't contan a table named "events".

Object reference not set to an instance of an object.

Hello,

Here is the error message:
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object. (Line 175)

Source Error:

Line 172: private void myDataGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e) {
Line 173: DataRowView drv = (DataRowView) e.Item.DataItem;
Line 174: System.Web.UI.WebControls.Image thumb =
(System.Web.UI.WebControls.Image) e.Item.FindControl("thumbnail");
Line 175: thumb.Attributes.Add("OnClick", "window.close()");

Can somebody help me?

Thanks!Hi,

check that you get Image with "thumbnail" name.

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
<asp:TemplateColumn>
<HeaderStyle CssClass="NormalBold"></HeaderStyle>
<ItemTemplate>
<asp:Image id="thumbnail" name="thumbnail" ImageUrl="<%=
GetBrowsePath((int) DataBinder.Eval(Container.DataItem,'itemId')) %>"
BorderWidth="0" Height="70" Width="100" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn
It still doesn't works.

"Natty Gur" <natty@.dao2com.com> schreef in bericht
news:#FLCVAkZDHA.2520@.TK2MSFTNGP09.phx.gbl...
> Hi,
> check that you get Image with "thumbnail" name.
> Natty Gur, CTO
> Dao2Com Ltd.
> 34th Elkalay st. Raanana
> Israel , 43000
> Phone Numbers:
> Office: +972-(0)9-7740261
> Fax: +972-(0)9-7740261
> Mobile: +972-(0)58-888377
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Wednesday, March 21, 2012

Object reference not set to an instance of an object.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

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

decimal price =
decimal.Parse(((TextBox)PropertyGridView.FooterRow .FindControl("PriceTextBox")).Text);

Any clue why this is happening?

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
AllProperies.PropertyGridView_RowCommand(Object sender,
GridViewCommandEventArgs e) in c:\Documents and Settings\Flynn\My
Documents\My Webs\CVM Web Portal\AllProperies.aspx.cs:70
System.Web.UI.WebControls.GridView.OnRowCommand(Gr idViewCommandEventArgs
e) +75
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
causesValidation, String validationGroup) +76
System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source, EventArgs
e) +88
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +86
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
eventArgument) +153
System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +172
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919Best guess is that FindControl is failing to find a control wth the id of
"PriceTextBox" so ur getting a null object back.

Of course, the other option is that PropertyGridView.FooterRow is null...

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Microsoft News Group" <mflynn@.cvmediaonline.comwrote in message
news:OLgUH6%23uGHA.4472@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
>
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
>
>
>
decimal price =
decimal.Parse(((TextBox)PropertyGridView.FooterRow .FindControl("PriceTextBox")).Text);
>
Any clue why this is happening?
>
>
>
Stack Trace:
>
[NullReferenceException: Object reference not set to an instance of an
object.]
AllProperies.PropertyGridView_RowCommand(Object sender,
GridViewCommandEventArgs e) in c:\Documents and Settings\Flynn\My
Documents\My Webs\CVM Web Portal\AllProperies.aspx.cs:70
System.Web.UI.WebControls.GridView.OnRowCommand(Gr idViewCommandEventArgs
e) +75
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
causesValidation, String validationGroup) +76
System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source,
EventArgs e) +88
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
+35
System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
+35
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +86
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
eventArgument) +153
>
System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +172
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919
>
>
>
>


When you're dealing with nulls/nothings, my advise is to break it down into
each piece, then rewrite the uber-single statement.

something like

FooterRow fr = PropertyGridView.FooterRow;
object o = fr.FindControl("PriceTextBox");
TextBox tb = (TextBox)o;
string s = tb.Text;
decimal price = decimal.Parse(s);

You'll usually find it that way.

Its not bad to put a
if(null!= someObject)
{
//do something//
}

in once a while too.

decimal price =

Quote:

Originally Posted by

>


decimal.Parse(((TextBox)PropertyGridView.FooterRow .FindControl("PriceTextBox
")).Text);

"Microsoft News Group" <mflynn@.cvmediaonline.comwrote in message
news:OLgUH6%23uGHA.4472@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
>
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
>
>
>
decimal price =
>


decimal.Parse(((TextBox)PropertyGridView.FooterRow .FindControl("PriceTextBox
")).Text);

Quote:

Originally Posted by

>
Any clue why this is happening?
>
>
>
Stack Trace:
>
[NullReferenceException: Object reference not set to an instance of an
object.]
AllProperies.PropertyGridView_RowCommand(Object sender,
GridViewCommandEventArgs e) in c:\Documents and Settings\Flynn\My
Documents\My Webs\CVM Web Portal\AllProperies.aspx.cs:70
>


System.Web.UI.WebControls.GridView.OnRowCommand(Gr idViewCommandEventArgs

Quote:

Originally Posted by

e) +75
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
causesValidation, String validationGroup) +76
System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source,


EventArgs

Quote:

Originally Posted by

e) +88
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)


+35

Quote:

Originally Posted by

System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)


+35

Quote:

Originally Posted by

System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +86
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
eventArgument) +153
>


System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.Rai
sePostBackEvent(String

Quote:

Originally Posted by

eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)


+172

Quote:

Originally Posted by

System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4919
>
>
>
>


Yea named the object wrong you are correct.

"Karl Seguin [MVP]" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME
netwrote in message news:%23nXsqL$uGHA.4612@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Best guess is that FindControl is failing to find a control wth the id of
"PriceTextBox" so ur getting a null object back.
>
Of course, the other option is that PropertyGridView.FooterRow is null...
>
Karl
>
--
http://www.openmymind.net/
http://www.fuelindustries.com/
>
>
"Microsoft News Group" <mflynn@.cvmediaonline.comwrote in message
news:OLgUH6%23uGHA.4472@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>Object reference not set to an instance of an object.
>Description: An unhandled exception occurred during the execution of the
>current web request. Please review the stack trace for more information
>about the error and where it originated in the code.
>>
>Exception Details: System.NullReferenceException: Object reference not
>set to an instance of an object.
>>
>>
>>
>decimal price =
>decimal.Parse(((TextBox)PropertyGridView.FooterRow .FindControl("PriceTextBox")).Text);
>>
>Any clue why this is happening?
>>
>>
>>
>Stack Trace:
>>
>[NullReferenceException: Object reference not set to an instance of an
>object.]
> AllProperies.PropertyGridView_RowCommand(Object sender,
>GridViewCommandEventArgs e) in c:\Documents and Settings\Flynn\My
>Documents\My Webs\CVM Web Portal\AllProperies.aspx.cs:70
>>
>System.Web.UI.WebControls.GridView.OnRowCommand(Gr idViewCommandEventArgs
>e) +75
> System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
>causesValidation, String validationGroup) +76
> System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source,
>EventArgs e) +88
> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
>+35
> System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
>EventArgs e) +117
> System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
>+35
> System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e) +86
> System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
>eventArgument) +153
>>
>System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String
>eventArgument) +7
> System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
>sourceControl, String eventArgument) +11
> System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
>+172
> System.Web.UI.Page.ProcessRequestMain(Boolean
>includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
>+4919
>>
>>
>>
>>


>
>

Friday, March 16, 2012

Object reference not set to an instance of an object.

Hello could someone please help me with this error?
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

<code>
Line 99: Else
Line 100: '####################
Line 101: Dim objCommand As OdbcCommand = New OdbcCommand("SELECT AuthKey FROM online_user WHERE Username='" & HttpContext.Current.Session("usr_Username").ToString() & "'", objConnection)
Line 102:
Line 103: objConnection.Open()
</code>


Thanks in adavnce

Hello,
The error is in this line HttpContext.Current.Session("usr_Username").ToString()
If the session is empty you will get that type of error. You can solve this problem by removing tostring method to be like this
HttpContext.Current.Session("usr_Username")

HTH
regards
Thanks smiling4ever,
The Session object was indeed empty.

Object reference not set to an instance of an object.

I am getting the following Error

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

Line 12: Dim profile As DataSet
Line 13: Profile = get_profile(UID)
Line 14: TB_FName.Text = profile.Tables.Item("uprofile").Rows.Item(0).Item("fname").ToString

Source File: c:\inetpub\wwwroot\createuser.aspx.vb Line: 14

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
createuser_aspx.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\createuser.aspx.vb:14
System.Web.UI.Control.OnLoad(EventArgs e) +102
System.Web.UI.Control.LoadRecursive() +45
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +952

aspx file imports the class profile
I am using a function get_profile

Imports Microsoft.VisualBasic
Imports system.data
Imports system.data.Odbc

Public class profile
public shared function get_profile (ByVal uid as Integer) as DataSet
Dim myConn As OdbcConnection = New OdbcConnection("connectionstring")
myConn.Open()
Dim SQL As String
SQL = "SELECT * from uprofile WHERE uid=" & uid
Dim DS_Profile As New DataSet
Dim DA_Profile As New OdbcDataAdapter
DA_Profile.SelectCommand = New OdbcCommand(SQL, myConn)
DA_Profile.Fill(DS_Profile)
Return DS_Profile
End Function

I assume that the profile variable will pick up the dataset as a return value
I do not really understand why the error is coming.

Thanks for the helpMake sure the Select statement really return a value based on the uid. If you are 100% sure that the select statement returns rows, make sure the "fname" field is not a DBNull.

Object reference not set to an instance of an object.

When I click button the following error occurs. What does this mean and how to remove it. Please help.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

Line 25: MsgBox("Hi there")
Line 26: 'Put user code to initialize the page here
Line 27: End Sub
Line 28:
Line 29: Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ServerClick

Source File: c:\inetpub\wwwroot\WebForm1.aspx.vb Line: 27

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
localhost.WebForm1.Button1_ServerClick(Object sender, EventArgs e) in c:\inetpub\wwwroot\WebForm1.aspx.vb:27
System.Web.UI.HtmlControls.HtmlInputButton.OnServerClick(EventArgs e) +108
System.Web.UI.HtmlControls.HtmlInputButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1263Can you post lines 1 to 30 of WebForm1.aspx.vb? Because your error message suggests that you've mistakenly deleted some lines of code. Before you post the code, pleaseread this.

Even beyond that, there seems to be a number of problems with your code. I don't think that you can use the MsgBox function in ASP.NET. And having WebForm1.aspx.vb directly within your wwwroot folder seems problematic. Are you working through a book that introduces ASP.NET, or gone through theonline tutorials? If not, you should, aseveryone new to ASP.NET needs to go through the basics.
There is something in your code behind file that is told to do something. The problem is, it is not on your aspx page to do it. It has something to do with that MsgBox. I am not sure of the entire procedure though.
See, Since this is the direct VB code there is no question of "<>" code blocks coming into picture. Since I have been working on VB6 for last 2 years so I find VB code very easy. When I was going through the Help File of ASP.net on creating web page I came across this code. It says that when You double click on the control the "...aspx.vb" file opens and You can write your code for button click or any such events there.
When I run the Page the code behind (in the aspx.vb module) doesn't run but when I put them in html it runs.
So my problem is how to run the code from aspx.vb module of Visualstudio.net package which seems so easy to code and understand for me.
Sounds like you are not telling the aspx page where the codebehind source is located. Top line should read something like this:
<%@. Page language="vb" CodeBehind="DesktopDefault.aspx.vb" AutoEventWireup="false" Explicit="True"Inherits="DotNetNuke.DesktopDefault" %>
which is thenamespace.classname