Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
1.50/5 (6 votes)
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
Updated 5-Oct-18 3:02am
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...

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.
 
Share this answer
 
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
[no name] 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.
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.
 
Share this answer
 
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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900