Click here to Skip to main content
13,254,754 members (49,407 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi
I am write some code.this is To log in the customer then find customer all data in another page.but execute code error is Object reference not set to an instance of an object. so Please help me the solve this problem....
Posted 2-Jul-12 19:56pm
Comments
Vani Kulkarni 3-Jul-12 1:04am
   
Please post your code, also mark the exact line where you are getting this error.
Arundhati Mohanty 17-Dec-13 1:25am
   
Hi i am workin in Silverlight5,VisualStudio2010,as i am new to it am not able to solve the problem,as i think i hv written all The codes correctly.
ERROR:
at SaveButton_Click(Object sender, RoutedEventArgs e) at System.Windows.Controls.Primitives.ButtonBase.OnClick() at System.Windows.Controls.Button.OnClick() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
Member 13109576 7-Aug-17 8:08am
   
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Data Source=\\SQLEXPRESS;Initial Catalog=AjaxSamples;Integrated Security=True"].ConnectionString);???????
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindRatingControl();
}
}
protected void RatingControlChanged(object sender, AjaxControlToolkit.RatingEventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into RatingDetails(Rate)values(@Rating)", con);
cmd.Parameters.AddWithValue("@Rating", ratingControl.CurrentRating);
cmd.ExecuteNonQuery();
con.Close();
BindRatingControl();
}
protected void BindRatingControl()
{
int total = 0;

DataTable dt = new DataTable();
con.Open();
SqlCommand cmd = new SqlCommand("Select Rate from RatingDetails", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
total += Convert.ToInt32(dt.Rows[i][0].ToString());
}
int average = total / (dt.Rows.Count);
ratingControl.CurrentRating = average;
lbltxt.Text = dt.Rows.Count + "user(s) have rated this article";
}
}
} }
Rahul Rajat Singh 3-Jul-12 2:56am
   
Show us the line where this exception is coming and we will try to find the null object for you.
Maria Norbert 20-Dec-13 0:43am
   
Hey Guyz...

Me to getting the Same error..

But when i rebuild Website the error Solved..

The Same thing happens to my Team Mates.. Please Help to resolve this...
padiharprem 25-Sep-14 7:23am
   
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.
padiharprem 25-Sep-14 7:25am
   
How open formview edit mode base on click edit button on gridview

Please solution provided to me i am try it but i am not get success
Member 11401758 4-Jun-15 22:43pm
   
please, can someone help me out with the following lines of codes that throws: System.NullReferenceException: Object reference not set to an instance of an object.


Public Sub createGrid_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles createGrid.Click

Dim watershedLayer As MapWindow.Interfaces.Layer
Dim watershedLayerHandle As Integer = Utilities.GetWatershedLayerHandle()
' If Not (watershedLayer Is Nothing) Then
If mw.Layers.IsValidHandle(watershedLayerHandle) Then
watershedLayer = mw.Layers.Item(watershedLayerHandle)
Else
If (findWatershedShapefile.ShowDialog = Windows.Forms.DialogResult.Cancel) Then Exit Sub
UpdateWatershedPath(findWatershedShapefile.FileName)
Dim layerName As String = "Watershed (" + System.IO.Path.GetFileName(WatershedShapePath) + ")"
watershedLayer = mw.Layers.Add(WatershedShapePath, layerName)
'watershedLayer.Name = layerName
End If
'End If
' Since this is "Create" grid it uses Nothing as the Grid layer so that GridForm will create one from scratch.
gridForm = New MWAGNPSLib.GridForm(mw, watershedLayer, Nothing)
gridForm.Show()
End Sub
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Its a normal error what you are getting.

Please provide the code for proper solution.

Hint: I your code there is some object which is NULL. and you will be trying to read some property value of that object.

This is the reason for the Object reference not set to an instance of an object.
  Permalink  
Comments
Member 10135342 3-Jul-13 6:09am
   
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using UserDetails;

namespace RegisterUser
{
public static class RegUser
{

public static int insert(user obj)
{

string cnstr = ConfigurationManager.ConnectionStrings["myCnstr"].ToString();
using (SqlConnection cn = new SqlConnection(cnstr))

here i got

Object reference not set to an instance of an object.



{
cn.Open();
string myquery = "INSERT INTO Registration(Name,address,EmailAddress,Password,Phoneno,Answer) Values (@Name,@address,@emailaddress,@Password,@Phoneno,@Answer)";
using (SqlCommand cmd = new SqlCommand(myquery, cn))
{
cmd.Parameters.AddWithValue("@Name", obj.Name);
cmd.Parameters.AddWithValue("@address", obj.address);
cmd.Parameters.AddWithValue("@emailaddress", obj.EmailAdress);
cmd.Parameters.AddWithValue("@Password", obj.Password);
cmd.Parameters.AddWithValue("@Phoneno", obj.PhoneNo);
cmd.Parameters.AddWithValue("@Answer", obj.Answer);

return cmd.ExecuteNonQuery();
// "INSERT INTO Registration(Name,address,Emailid,PhoneNum)( VALUES(@Name,@address,@emailaddress,@Password,@Phoneno,@Answer)

}
}
}
}
}
Member 12678665 6-Sep-16 7:42am
   
please send object instance
2irfanshaikh 3-Jul-13 11:14am
   
Please send your config file
Member 13299570 8-Jul-17 5:56am
   
<connectionstrings>
<add name="caredementia" connectionString="Data Source=ASUS-PC\SQLEXPRESS;Initial Catalog=caredementia;Integrated Security=True" providerName="System.Data.SqlClient"/>

<system.web>
Afzaal Ahmad Zeeshan 12-Jun-15 9:15am
   
Not always a null is the problem. A type mismatch can also be the problem.

My vote of 4.
Member 13299570 8-Jul-17 5:57am
   
i was check all the type mimatch's
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

When ever you try to retrieve data from a Null object you will get this error. Before retrieving the data from any object check for NULL.
  Permalink  
Comments
Afzaal Ahmad Zeeshan 12-Jun-15 9:17am
   
That can work, but sometimes a type-mismatch can also trigger this exception. But a good suggestion to test the value.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.171114.1 | Last Updated 12 Jun 2015
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100